Skip to content

Commit e3da7fc

Browse files
committed
fix too many local variables for static method
1 parent 1ca6da2 commit e3da7fc

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

CSharp.lua/LuaAst/LuaTypeDeclarationSyntax.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,9 @@ protected void AddResultTable(LuaKeyValueTableItemSyntax item) {
187187

188188
private void CheckTooManyVariables(bool isLocalOrUpvalues) {
189189
if (!hasTooManyLocalVariables_) {
190+
local_.Variables.Add(LuaIdentifierNameSyntax.MorenManyLocalVarTempTable);
190191
methodList_.Statements.Add(new LuaShortCommentStatement(isLocalOrUpvalues ? " too many local variables (limit is 200)" : "too many upvalues (limit is 60)"));
191-
methodList_.Statements.Add(new LuaLocalVariableDeclaratorSyntax(LuaIdentifierNameSyntax.MorenManyLocalVarTempTable, LuaTableExpression.Empty));
192+
methodList_.Statements.Add(LuaIdentifierNameSyntax.MorenManyLocalVarTempTable.Assignment(LuaTableExpression.Empty));
192193
hasTooManyLocalVariables_ = true;
193194
}
194195
}

CSharp.lua/LuaSyntaxNodeTransform.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2860,15 +2860,8 @@ private IMethodSymbol GetDelegateTargetMethodSymbol(CSharpSyntaxNode node) {
28602860
}
28612861
}
28622862

2863-
private LuaExpressionSyntax BuildDelegateNameExpression(IMethodSymbol symbol, LuaExpressionSyntax target, LuaExpressionSyntax name, CSharpSyntaxNode node) {
2863+
private void CheckDelegateBind(IMethodSymbol symbol, CSharpSyntaxNode node, ref LuaExpressionSyntax nameExpression) {
28642864
const int kReturnParameterIndex = int.MaxValue;
2865-
LuaExpressionSyntax nameExpression;
2866-
if (symbol.IsStatic) {
2867-
nameExpression = name;
2868-
} else {
2869-
nameExpression = new LuaInvocationExpressionSyntax(LuaIdentifierNameSyntax.DelegateMake, target, name);
2870-
}
2871-
28722865
if (symbol.IsGenericMethod) {
28732866
var originalDefinition = symbol.OriginalDefinition;
28742867
if (!originalDefinition.Equals(symbol)) {
@@ -2945,18 +2938,21 @@ private LuaExpressionSyntax BuildDelegateNameExpression(IMethodSymbol symbol, Lu
29452938
string bindMethodName = LuaIdentifierNameSyntax.DelegateBind.ValueText + placeholders.Count;
29462939
var invocationExpression = new LuaInvocationExpressionSyntax(bindMethodName, nameExpression);
29472940
invocationExpression.AddArguments(placeholders.Select(i => i.Build(this)));
2948-
return invocationExpression;
2941+
nameExpression = invocationExpression;
2942+
return;
29492943
}
29502944
} else if (symbol.Parameters.Length == 2) {
29512945
if (placeholders.Count == 2) {
29522946
if (placeholders[0].TypeParameterIndex == 2 && placeholders[1].TypeParameterIndex == 1) {
29532947
string bindMethodName = LuaIdentifierNameSyntax.DelegateBind.ValueText + "2_1";
2954-
return new LuaInvocationExpressionSyntax(bindMethodName, nameExpression);
2948+
nameExpression = new LuaInvocationExpressionSyntax(bindMethodName, nameExpression);
2949+
return;
29552950
}
29562951
} else if (placeholders.Count == 1) {
29572952
if (placeholders.First().TypeParameterIndex == 2) {
29582953
string bindMethodName = LuaIdentifierNameSyntax.DelegateBind.ValueText + "0_2";
2959-
return new LuaInvocationExpressionSyntax(bindMethodName, nameExpression);
2954+
nameExpression = new LuaInvocationExpressionSyntax(bindMethodName, nameExpression);
2955+
return;
29602956
}
29612957
}
29622958
}
@@ -2967,7 +2963,16 @@ private LuaExpressionSyntax BuildDelegateNameExpression(IMethodSymbol symbol, Lu
29672963
}
29682964
}
29692965
}
2966+
}
29702967

2968+
private LuaExpressionSyntax BuildDelegateNameExpression(IMethodSymbol symbol, LuaExpressionSyntax target, LuaExpressionSyntax name, CSharpSyntaxNode node) {
2969+
LuaExpressionSyntax nameExpression;
2970+
if (symbol.IsStatic) {
2971+
nameExpression = name;
2972+
} else {
2973+
nameExpression = new LuaInvocationExpressionSyntax(LuaIdentifierNameSyntax.DelegateMake, target, name);
2974+
}
2975+
CheckDelegateBind(symbol, node, ref nameExpression);
29712976
return nameExpression;
29722977
}
29732978

@@ -2990,6 +2995,9 @@ private LuaExpressionSyntax GetMethodNameExpression(IMethodSymbol symbol, NameSy
29902995
}
29912996
return new LuaInternalMethodExpressionSyntax(methodName);
29922997
}
2998+
if (CurTypeSymbol.IsContainsInternalSymbol(symbol) && IsMoreThanLocalVariables(symbol)) {
2999+
return LuaIdentifierNameSyntax.MorenManyLocalVarTempTable.MemberAccess(methodName);
3000+
}
29933001
return methodName;
29943002
} else {
29953003
if (IsInternalMember(symbol)) {

0 commit comments

Comments
 (0)