Skip to content
This repository has been archived by the owner on Mar 9, 2021. It is now read-only.

When using [NamedValuesAttribute] on an enum, that enum's values are not compiled correctly when used as default parameters #439

Open
craigkovatch opened this issue Dec 22, 2015 · 3 comments

Comments

@craigkovatch
Copy link

[NamedValuesAttribute]
public enum HorizontalAlign {
  Left,
  Center,
  Right
}

public string someMethod(bool doSomething, HorizontalAlign align = HorizontalAlign.Center) {
  string direction = align.ToString();
  ...
}

When compiled to JS, this will be defaulted to 'null' rather than "Center", yielding an NPE.

@n9
Copy link

n9 commented Dec 22, 2015

Which version are you using?

This code:

[NamedValuesAttribute]
public enum HorizontalAlign
{
    Left,
    Center,
    Right
}

class X
{
    public string someMethod2()
    {
        return someMethod(false);
    }


    public string someMethod(bool doSomething, HorizontalAlign align = HorizontalAlign.Center)
    {
        return align.ToString();
    }
}

Compiles to:

    ss.initClass($$X, $asm, {
        $someMethod2: function() {
            return this.$someMethod(false, 1);
        },
        $someMethod: function(doSomething, align) {
            return align.toString();
        }
    });
    ss.initEnum($HorizontalAlign, $asm, { left: 'left', center: 'center', right: 'right' }, true);

@craigkovatch
Copy link
Author

We're on 2.6.2. But that's still a very similar error -- line 3 of that compiled output should be return this.$someMethod(false, 'center'); The parameter should be 'center', not 1, i.e. the NamedValuesAttribute tag is having no effect when used with defaulted parameters.

@n9
Copy link

n9 commented Dec 22, 2015

Yes, it's wrong.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants