vrchat-community / UdonSharp

A compiler for compiling C# to Udon assembly
https://udonsharp.docs.vrchat.com
MIT License
462 stars 50 forks source link

Enum type parameters with a default value fail to compile. #72

Open synergiance opened 1 year ago

synergiance commented 1 year ago

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.

Misaka-L commented 1 year ago

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