yanghuan/CSharp.lua

Small app crashes compiler with `-c` classic switch

joelverhagen opened this issue · 1 comments

This small class crashes with -c. It works fine without -c.

public class Baz
{
    private static object? Foo { get; set; }
    private static object Bar = new object();
}

Error:

CSharpLua.BugErrorException: SourceLocation(C:\z\Git\joelverhagen\FactorioTools\src\FactorioTools\OilField\Steps\InitializeFLUTE.cs@1:1)"public class Baz
{
    private static object? Foo { get; set; }
    private static object Bar = new object();
}": Compiler has a bug, thanks to commit issue at https://github.com/yanghuan/CSharp.lua/issue
 ---> System.Diagnostics.Contracts.ContractException
 ---> System.ApplicationException
   at CSharpLua.LuaSyntaxGenerator.<>c.<.cctor>b__29_0(Object _, ContractFailedEventArgs e) in C:\z\Git\joelverhagen\CSharp.lua\CSharp.lua\LuaSyntaxGenerator.cs:line 139
   at System.Runtime.CompilerServices.ContractHelper.RaiseContractFailedEvent(ContractFailureKind failureKind, String userMessage, String conditionText, Exception innerException)
   --- End of inner exception stack trace ---
   at System.Runtime.CompilerServices.ContractHelper.RaiseContractFailedEvent(ContractFailureKind failureKind, String userMessage, String conditionText, Exception innerException)
   at System.Diagnostics.Contracts.Contract.ReportFailure(ContractFailureKind failureKind, String userMessage, String conditionText, Exception innerException)
   at CSharpLua.LuaSyntaxGenerator.IsStaticCtorField(ISymbol symbol) in C:\z\Git\joelverhagen\CSharp.lua\CSharp.lua\LuaSyntaxGenerator.cs:line 1769
   at System.Linq.Enumerable.WhereArrayIterator`1.MoveNext()
   at CSharpLua.LuaSyntaxGenerator.GetStaticCtorFieldNeedUpValueCount(IMethodSymbol methodSymbol) in C:\z\Git\joelverhagen\CSharp.lua\CSharp.lua\LuaSyntaxGenerator.cs:line 1786
   at CSharpLua.LuaSyntaxGenerator.GetMethodMaxUpValueCount(IMethodSymbol methodSymbol) in C:\z\Git\joelverhagen\CSharp.lua\CSharp.lua\LuaSyntaxGenerator.cs:line 1805
   at CSharpLua.LuaSyntaxGenerator.<IsMoreThanUpValueStaticCtorField>b__155_0(INamedTypeSymbol definitionType) in C:\z\Git\joelverhagen\CSharp.lua\CSharp.lua\LuaSyntaxGenerator.cs:line 1758
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at CSharpLua.LuaSyntaxGenerator.IsMoreThanUpValueStaticCtorField(ISymbol symbol) in C:\z\Git\joelverhagen\CSharp.lua\CSharp.lua\LuaSyntaxGenerator.cs:line 1754
   at CSharpLua.LuaSyntaxNodeTransform.IsMoreThanUpValueStaticInitField(ISymbol symbol) in C:\z\Git\joelverhagen\CSharp.lua\CSharp.lua\LuaSyntaxNodeTransform.Helper.cs:line 445
   at CSharpLua.LuaSyntaxNodeTransform.VisitBaseFieldDeclarationSyntax(BaseFieldDeclarationSyntax node) in C:\z\Git\joelverhagen\CSharp.lua\CSharp.lua\LuaSyntaxNodeTransform.cs:line 932
   at CSharpLua.LuaSyntaxNodeTransform.VisitFieldDeclaration(FieldDeclarationSyntax node) in C:\z\Git\joelverhagen\CSharp.lua\CSharp.lua\LuaSyntaxNodeTransform.cs:line 964
   at Microsoft.CodeAnalysis.CSharp.Syntax.FieldDeclarationSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
   at CSharpLua.LuaSyntaxNodeTransform.BuildTypeMembers(LuaTypeDeclarationSyntax typeDeclaration, TypeDeclarationSyntax node) in C:\z\Git\joelverhagen\CSharp.lua\CSharp.lua\LuaSyntaxNodeTransform.cs:line 298
   at CSharpLua.LuaSyntaxNodeTransform.BuildTypeDeclaration(INamedTypeSymbol typeSymbol, TypeDeclarationSyntax node, LuaTypeDeclarationSyntax typeDeclaration) in C:\z\Git\joelverhagen\CSharp.lua\CSharp.lua\LuaSyntaxNodeTransform.cs:line 404
   at CSharpLua.LuaSyntaxNodeTransform.VisitTypeDeclaration(INamedTypeSymbol typeSymbol, TypeDeclarationSyntax node, LuaTypeDeclarationSyntax typeDeclaration) in C:\z\Git\joelverhagen\CSharp.lua\CSharp.lua\LuaSyntaxNodeTransform.cs:line 507
   at CSharpLua.LuaSyntaxNodeTransform.VisitClassDeclaration(ClassDeclarationSyntax node) in C:\z\Git\joelverhagen\CSharp.lua\CSharp.lua\LuaSyntaxNodeTransform.cs:line 574
   at Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax.Accept[TResult](CSharpSyntaxVisitor`1 visitor)
   at CSharpLua.LuaSyntaxNodeTransform.BlockCommonNode.Visit(LuaSyntaxNodeTransform transform) in C:\z\Git\joelverhagen\CSharp.lua\CSharp.lua\LuaSyntaxNodeTransform.cs:line 1351
   --- End of inner exception stack trace ---
   at CSharpLua.LuaSyntaxGenerator.Create(Boolean isSingleFile) in C:\z\Git\joelverhagen\CSharp.lua\CSharp.lua\LuaSyntaxGenerator.cs:line 240
   at CSharpLua.LuaSyntaxGenerator.GenerateSingleFile(String outFile, String outFolder, IEnumerable`1 luaSystemLibs) in C:\z\Git\joelverhagen\CSharp.lua\CSharp.lua\LuaSyntaxGenerator.cs:line 286
   at CSharpLua.Compiler.Compile() in C:\z\Git\joelverhagen\CSharp.lua\CSharp.lua\Compiler.cs:line 127
   at CSharpLua.Program.Main(String[] args) in C:\z\Git\joelverhagen\CSharp.lua\CSharp.lua.Launcher\Program.cs:line 90

It appears the problem is because this method has a MethodKind.SharedConstructor passed in and the assert fails. Nope, that's wrong.

It appears to be a backing field failing an IsFromCode assertion. I commented it out and found the declarator is null.

image

It's this assertion failing:

Contract.Assert(symbol.IsFromCode());