Skip to content

Commit

Permalink
fix #485
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghuan committed Jan 9, 2024
1 parent 8b9c0dc commit 3822074
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions CSharp.lua/LuaSyntaxNodeTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1239,20 +1239,24 @@ public override LuaSyntaxNode VisitIndexerDeclaration(IndexerDeclarationSyntax n
var indexName = GetMemberName(symbol);
var parameterList = node.ParameterList.Accept<LuaParameterListSyntax>(this);

void Fill(Action<LuaFunctionExpressionSyntax, LuaPropertyOrEventIdentifierNameSyntax> action) {
void Fill(IMethodSymbol accessorSymbol, Action<LuaFunctionExpressionSyntax, LuaPropertyOrEventIdentifierNameSyntax> action) {
var methodInfo = new MethodInfo(accessorSymbol);
methodInfos_.Push(methodInfo);
var function = new LuaFunctionExpressionSyntax();
function.AddParameter(LuaIdentifierNameSyntax.This);
function.ParameterList.Parameters.AddRange(parameterList.Parameters);
var name = new LuaPropertyOrEventIdentifierNameSyntax(true, indexName);
PushFunction(function);
action(function, name);
PopFunction();
methodInfos_.Pop();
CurType.AddMethod(name, function, isPrivate);
}

if (node.AccessorList != null) {
foreach (var accessor in node.AccessorList.Accessors) {
Fill((function, name) => {
var accessorSymbol = semanticModel_.GetDeclaredSymbol(accessor);
Fill(accessorSymbol, (function, name) => {
bool isGet = accessor.IsKind(SyntaxKind.GetAccessorDeclaration);
if (accessor.Body != null) {
var block = accessor.Body.Accept<LuaBlockSyntax>(this);
Expand All @@ -1272,7 +1276,7 @@ void Fill(Action<LuaFunctionExpressionSyntax, LuaPropertyOrEventIdentifierNameSy
});
}
} else {
Fill((function, name) => {
Fill(symbol.GetMethod, (function, name) => {
var bodyExpression = node.ExpressionBody.AcceptExpression(this);
function.AddStatement(new LuaReturnStatementSyntax(bodyExpression));
});
Expand Down

0 comments on commit 3822074

Please sign in to comment.