Skip to content

Commit

Permalink
fix #462
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghuan committed Jan 24, 2024
1 parent c1c4185 commit 615ddfd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
1 change: 1 addition & 0 deletions CSharp.lua/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ private LuaSyntaxGenerator GetGenerator() {
IsInlineSimpleProperty = IsInlineSimpleProperty,
IsPreventDebugObject = IsPreventDebugObject,
IsNotConstantForEnum = IsNotConstantForEnum,
IsNoConcurrent = IsNoConcurrent,
};
return new LuaSyntaxGenerator(codes, libs, cscArguments_, Metas, setting);
}
Expand Down
55 changes: 28 additions & 27 deletions CSharp.lua/LuaSyntaxNodeTransform.Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -876,8 +876,12 @@ private bool IsImportTypeNameEnable(INamedTypeSymbol symbol) {
if (symbol.IsTypeParameterExists() && !IsCurMethodTypeArgument(symbol)) {
return false;
}
return true;
}

if (!IsNoneGenericTypeCounter && CurTypeDeclaration?.TypeSymbol?.IsGenericType == true) {
return false;
}

return true;
}

Expand Down Expand Up @@ -1046,30 +1050,30 @@ internal void ImportGenericTypeName(ref LuaExpressionSyntax luaExpression, IType
if (!IsNoImportTypeName && !CurTypeSymbol.EQ(symbol) && !IsCurMethodTypeArgument(symbol)) {
var invocationExpression = (LuaInvocationExpressionSyntax)luaExpression;
string newName = GetGenericTypeImportName(invocationExpression, out var argumentTypeNames);
if (!IsLocalVarExistsInCurMethod(newName)) {
bool success;
if (!symbol.IsTypeParameterExists()) {
bool success = false;
if (!symbol.IsTypeParameterExists()) {
if (!IsLocalVarExistsInCurMethod(newName)) {
success = AddGenericImport(invocationExpression, newName, argumentTypeNames, symbol.IsAbsoluteFromCode());
} else {
success = CurTypeDeclaration.TypeDeclaration.AddGenericImport(invocationExpression, newName, argumentTypeNames, symbol.IsAbsoluteFromCode(), out var declare);
if (declare != null) {
CheckGenericDeclareTypeArgument(declare, invocationExpression, symbol);
bool hasAdd = generator_.AddGenericImportDepend(CurTypeDeclaration.TypeSymbol, symbol.OriginalDefinition as INamedTypeSymbol);
if (hasAdd && CurCompilationUnit.IsUsingDeclareConflict(invocationExpression)) {
declare.IsFromGlobal = true;
declare.InvocationExpression = new LuaInvocationExpressionSyntax(
LuaIdentifierNameSyntax.Global.MemberAccess(invocationExpression.Expression),
invocationExpression.ArgumentList.Arguments);
}
if (declare.IsFromGlobal) {
CurTypeDeclaration.TypeDeclaration.AddGlobalParameter();
}
}
}
if (success) {
luaExpression = newName;
} else {
success = CurTypeDeclaration.TypeDeclaration.AddGenericImport(invocationExpression, newName, argumentTypeNames, symbol.IsAbsoluteFromCode(), out var declare);
if (declare != null) {
CheckGenericDeclareTypeArgument(declare, invocationExpression, symbol);
bool hasAdd = generator_.AddGenericImportDepend(CurTypeDeclaration.TypeSymbol, symbol.OriginalDefinition as INamedTypeSymbol);
if (hasAdd && CurCompilationUnit.IsUsingDeclareConflict(invocationExpression)) {
declare.IsFromGlobal = true;
declare.InvocationExpression = new LuaInvocationExpressionSyntax(
LuaIdentifierNameSyntax.Global.MemberAccess(invocationExpression.Expression),
invocationExpression.ArgumentList.Arguments);
}
if (declare.IsFromGlobal) {
CurTypeDeclaration.TypeDeclaration.AddGlobalParameter();
}
}
}
if (success) {
luaExpression = newName;
}
}
}

Expand All @@ -1080,14 +1084,14 @@ private void CheckGenericDeclareTypeArgument(GenericUsingDeclare declare, LuaInv
foreach (var typeArgument in nameTypeSymbol.TypeArguments) {
if (typeArgument.Kind != SymbolKind.TypeParameter && typeArgument.IsFromCode()) {
var argumentExpression = invocation.ArgumentList.Arguments[i];
if (argumentExpression is LuaImportNameSyntax identifier) {
if (argumentExpression is LuaIdentifierNameSyntax identifier) {
string name = identifier.ValueText;
int j = name.IndexOf('.');
if (j != -1) {
name = name.Substring(0, j);
}
if (!CurTypeDeclaration.TypeDeclaration.IsGenericImportExists(name)) {
invocation.ArgumentList.Arguments[i] = LuaIdentifierNameSyntax.Global.MemberAccess(identifier.TypeName);
invocation.ArgumentList.Arguments[i] = LuaIdentifierNameSyntax.Global.MemberAccess(identifier);
declare.IsFromGlobal = true;
}
}
Expand Down Expand Up @@ -1401,10 +1405,7 @@ private LuaDocumentStatement BuildDocumentationComment(CSharpSyntaxNode node) {
}

private LuaExpressionSyntax BuildInheritTypeName(ITypeSymbol baseType) {
++noImportTypeNameCounter_;
var baseTypeName = GetTypeName(baseType);
--noImportTypeNameCounter_;
return baseTypeName;
return GetTypeNameWithoutImport(baseType);
}

private LuaExpressionSyntax GetRecordInterfaceTypeName(INamedTypeSymbol recordType) {
Expand Down

0 comments on commit 615ddfd

Please sign in to comment.