Skip to content

Commit

Permalink
fix #494
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghuan committed Jan 23, 2024
1 parent d20d217 commit c1c4185
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions CSharp.lua/LuaSyntaxGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,13 @@ private void TryAddExtend(INamedTypeSymbol super, INamedTypeSymbol children, boo
}
}

private HashSet<INamedTypeSymbol> GetExtendChildren(INamedTypeSymbol typeSymbol) {
if (typeSymbol.IsGenericType) {
typeSymbol = typeSymbol.OriginalDefinition;
}
return extends_.GetOrDefault(typeSymbol);
}

internal LuaIdentifierNameSyntax GetMemberName(ISymbol symbol) {
Utility.CheckOriginalDefinition(ref symbol);
var name = memberNames_.GetOrDefault(symbol);
Expand Down Expand Up @@ -1182,7 +1189,7 @@ private void CheckRefactorNames() {

private void RefactorCurTypeSymbol(ISymbol symbol, HashSet<ISymbol> alreadyRefactorSymbols) {
INamedTypeSymbol typeSymbol = symbol.ContainingType;
var children = extends_.GetOrDefault(typeSymbol);
var children = GetExtendChildren(typeSymbol);
string newName = GetRefactorName(typeSymbol, children, symbol);
RefactorName(symbol, newName, alreadyRefactorSymbols);
}
Expand All @@ -1191,7 +1198,7 @@ private bool RefactorInterfaceSymbol(ISymbol symbol, HashSet<ISymbol> alreadyRef
if (symbol.IsFromCode()) {
INamedTypeSymbol typeSymbol = symbol.ContainingType;
Contract.Assert(typeSymbol.TypeKind == TypeKind.Interface);
var children = extends_.GetOrDefault(typeSymbol);
var children = GetExtendChildren(typeSymbol);
string newName = GetRefactorName(null, children, symbol);
if (children != null) {
foreach (INamedTypeSymbol child in children) {
Expand Down Expand Up @@ -1227,7 +1234,7 @@ private void RefactorName(ISymbol symbol, string newName, HashSet<ISymbol> alrea
}

private void RefactorChildrenOverridden(ISymbol originalSymbol, INamedTypeSymbol curType, string newName, HashSet<ISymbol> alreadyRefactorSymbols) {
var children = extends_.GetOrDefault(curType);
var children = GetExtendChildren(curType);
if (children != null) {
foreach (INamedTypeSymbol child in children) {
var curSymbol = child.GetMembers(originalSymbol.Name).FirstOrDefault(i => i.IsOverridden(originalSymbol));
Expand Down Expand Up @@ -1400,7 +1407,7 @@ private bool IsInnerNameEnable(INamedTypeSymbol typeSymbol, string newName, bool
}

private bool IsInnerNameEnableOfChildren(INamedTypeSymbol typeSymbol, string newName, bool isPrivate) {
var children = extends_.GetOrDefault(typeSymbol);
var children = GetExtendChildren(typeSymbol);
if (children != null) {
foreach (INamedTypeSymbol child in children) {
if (!IsNameEnableOfCurAndChildren(child, newName, isPrivate)) {
Expand Down Expand Up @@ -1855,7 +1862,7 @@ internal bool HasStaticCtor(INamedTypeSymbol typeSymbol) {
}

internal bool IsExtendExists(INamedTypeSymbol typeSymbol) {
var set = extends_.GetOrDefault(typeSymbol);
var set = GetExtendChildren(typeSymbol);
return set?.Count > 0;
}

Expand Down
2 changes: 1 addition & 1 deletion CSharp.lua/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ public static bool Is(this ITypeSymbol left, ITypeSymbol right) {

private static void CheckSymbolDefinition<T>(ref T symbol) where T : class, ISymbol {
var originalDefinition = (T)symbol.OriginalDefinition;
if (originalDefinition != symbol) {
if (!originalDefinition.EQ(symbol)) {
symbol = originalDefinition;
}
}
Expand Down

0 comments on commit c1c4185

Please sign in to comment.