Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum.GetValues fails with attempt to call a nil value (method 'getIsEnum') #463

Open
joelverhagen opened this issue Jan 3, 2024 · 0 comments

Comments

@joelverhagen
Copy link
Contributor

joelverhagen commented Jan 3, 2024

Repro

namespace Knapcode
{
    public static class ClassA
    {
        public static void MyMethod()
        {
            Console.WriteLine(string.Join(", ", Enum.GetValues<MyEnum>()));
        }
    }

    public enum MyEnum
    {
        Foo,
        Bar,
    }
}

Generated Lua:

-- Generated by CSharp.lua Compiler
do
local System = System
System.namespace("Knapcode", function (namespace)
  namespace.class("ClassA", function (namespace)
    local MyMethod
    MyMethod = function ()
      System.Console.WriteLine(System.String.JoinEnumerable(", ", System.Enum.GetValues(System.Int32)))
    end
    return {
      MyMethod = MyMethod
    }
  end)

end)

end
System.init({
  types = {
    "Knapcode.ClassA"
  }
})

If you call MyMethod you get this error:

C:\Users\joelv\Downloads\lua-5.3.6_Win64_bin\lua53.exe: .\out.lua:4274: attempt to call a nil value (method 'getIsEnum')
stack traceback:
        .\out.lua:4274: in field 'GetValues'
        .\out.lua:19537: in field 'MyMethod'
        .\main.lua:3: in main chunk
        [C]: in ?

This can be worked around with a source generator for all values or manually listing all values in source.

joelverhagen added a commit to joelverhagen/FactorioTools that referenced this issue Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant