@@ -840,6 +840,25 @@ public static CppSourceLocation GetSourceLocation(CXSourceLocation start)
840840 return new CppSourceLocation ( fileNameStr , ( int ) offset , ( int ) line , ( int ) column ) ;
841841 }
842842
843+ private static bool IsAnonymousTypeUsed ( CppType type , CppType anonymousType )
844+ {
845+ return IsAnonymousTypeUsed ( type , anonymousType , new HashSet < CppType > ( ) ) ;
846+ }
847+
848+ private static bool IsAnonymousTypeUsed ( CppType type , CppType anonymousType , HashSet < CppType > visited )
849+ {
850+ if ( ! visited . Add ( type ) ) return false ;
851+
852+ if ( ReferenceEquals ( type , anonymousType ) ) return true ;
853+
854+ if ( type is CppTypeWithElementType typeWithElementType )
855+ {
856+ return IsAnonymousTypeUsed ( typeWithElementType . ElementType , anonymousType ) ;
857+ }
858+
859+ return false ;
860+ }
861+
843862 private CppField VisitFieldOrVariable ( CppContainerContext containerContext , CXCursor cursor , void * data )
844863 {
845864 var fieldName = CXUtil . GetCursorSpelling ( cursor ) ;
@@ -849,10 +868,11 @@ private CppField VisitFieldOrVariable(CppContainerContext containerContext, CXCu
849868 CppField cppField ;
850869 // This happen in the type is anonymous, we create implicitly a field for it, but if type is the same
851870 // we should reuse the anonymous field we created just before
852- if ( previousField != null && previousField . IsAnonymous && ReferenceEquals ( previousField . Type , type ) )
871+ if ( previousField != null && previousField . IsAnonymous && IsAnonymousTypeUsed ( type , previousField . Type ) )
853872 {
854873 cppField = previousField ;
855874 cppField . Name = fieldName ;
875+ cppField . Type = type ;
856876 cppField . Offset = cursor . OffsetOfField / 8 ;
857877 }
858878 else
0 commit comments