neolithos / neolua

A Lua implementation for the Dynamic Language Runtime (DLR).
https://neolua.codeplex.com/
Apache License 2.0
466 stars 76 forks source link

Using multiple discards leads to compilation error #174

Closed powercode closed 1 year ago

powercode commented 1 year ago

NeoLua Version: latest

Example to reproduce:

Message: 
Test method LuaDLR.Test.Expressions.TestAssign03 threw exception: 
System.InvalidOperationException: variable '_' of type 'System.Object' referenced from scope 'Test', but it is not defined

  Stack Trace: 
VariableBinder.Reference(ParameterExpression node, VariableStorageKind storage)
VariableBinder.VisitParameter(ParameterExpression node)
VariableBinder.Visit(Expression node)
ExpressionVisitor.VisitBinary(BinaryExpression node)
VariableBinder.Visit(Expression node)
ExpressionVisitor.Visit(ReadOnlyCollection`1 nodes)
VariableBinder.VisitBlock(BlockExpression node)
VariableBinder.Visit(Expression node)
ExpressionVisitor.Visit(ReadOnlyCollection`1 nodes)
VariableBinder.VisitLambda[T](Expression`1 node)
VariableBinder.Visit(Expression node)
VariableBinder.VisitUnary(UnaryExpression node)
VariableBinder.Visit(Expression node)
ExpressionVisitor.VisitArguments(IArgumentProvider nodes)
ExpressionVisitor.VisitDynamic(DynamicExpression node)
VariableBinder.Visit(Expression node)
ExpressionVisitor.Visit(ReadOnlyCollection`1 nodes)
VariableBinder.VisitLambda[T](Expression`1 node)
VariableBinder.Visit(Expression node)
LambdaCompiler.Compile(LambdaExpression lambda, DebugInfoGenerator debugInfoGenerator)
Lua.CompileChunkCore(ILuaLexer lex, LuaCompileOptions options, IEnumerable`1 args) line 305
Lua.CompileChunk(TextReader tr, String name, LuaCompileOptions options, KeyValuePair`2[] args) line 226
LuaGlobal.DoChunk(TextReader tr, String name, KeyValuePair`2[] args) line 109
LuaGlobal.DoChunk(String code, String name, KeyValuePair`2[] args) line 79
TestHelper.TestCode(String code, Object[] expectedResult) line 37
Expressions.TestAssign03() line 1504

  Standard Output: 
Test: 
function Test()
   local _, _, x = 1, 2, 3;
   return x;
end;

return Test()

==================================================================
.Lambda test<System.Func`2[Neo.IronLua.LuaTable,Neo.IronLua.LuaResult]>(Neo.IronLua.LuaTable $_G) {
    .Block() {
        .Dynamic SetMember Test(
            (System.Object)$_G,
            (System.Object).Lambda Test<System.Func`1[Neo.IronLua.LuaResult]>);
        .Goto #return { .Dynamic Convert Neo.IronLua.LuaResult(.Dynamic Invoke(.Dynamic GetMember Test((System.Object)$_G))) };
        .Label
            Neo.IronLua.LuaResult.Empty
        .LabelTarget #return:
    }
}

.Lambda Test<System.Func`1[Neo.IronLua.LuaResult]>() {
    .Block(
        System.Object $_,
        System.Object $x) {
        .Block(
            System.Int32 $var1,
            System.Int32 $var2,
            System.Int32 $var3) {
            $var1 = 1;
            $var2 = 2;
            $var3 = 3;
            $_ = (System.Object)$var1;
            $_ = (System.Object)$var2;
            $x = (System.Object)$var3
        };
        .Goto #return { .New Neo.IronLua.LuaResult($x) };
        .Label
            Neo.IronLua.LuaResult.Empty
        .LabelTarget #return:
    }
}
===============================================================================