UdonSharp icon indicating copy to clipboard operation
UdonSharp copied to clipboard

Enum type parameters with a default value fail to compile.

Open synergiance opened this issue 3 years ago • 1 comments

Describe the bug in detail: When a method takes an enum type as a parameter, and also gives it a default value, UdonSharp's compiler seems to forget that it is the same enum type being passed in. (System.ArgumentException: Type provided must be an Enum.)

Provide steps/code to reproduce the bug: Declare an enum:

public enum MyEnum {
    MyFirstValue, MySecondValue
}

Declare a method with that enum type as a parameter and uses a default value:

public void MyMethod(MyEnum myEnumParameter = MyEnum.MyFirstValue) {
    // Method content
}

Call that method:

MyMethod(MyEnum.MySecondValue);

Expected behavior: Program compiles and runs

Additional Information: This was tested across behaviors. I did not actually test whether it happens within the same behavior.

synergiance avatar Oct 26 '22 20:10 synergiance

Same problem and it happens within the same behavior.

namespace A320VAU.ND.Pages
{
    // ....
    public class MapDisplay : UdonSharpBehaviour
    {
        // ....
        private void InstantiateMarkers(int range, EFISVisibilityType efisVisibilityType = EFISVisibilityType.NONE)
        {
            // ....
        }

        public void SetRange(int range) => InstantiateMarkers(range, GetVisibilityType());
        public void SetVisibilityType(EFISVisibilityType visibilityType) => InstantiateMarkers(Range, visibilityType);

        // ....
    }

    public enum EFISVisibilityType
    {
        CSTR,
        WPT,
        VORDME,
        NDB,
        APPT,
        NONE
    }
}

image image image

Misaka-L avatar Apr 28 '23 16:04 Misaka-L