@@ -840,6 +840,25 @@ public static CppSourceLocation GetSourceLocation(CXSourceLocation start)
840
840
return new CppSourceLocation ( fileNameStr , ( int ) offset , ( int ) line , ( int ) column ) ;
841
841
}
842
842
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
+
843
862
private CppField VisitFieldOrVariable ( CppContainerContext containerContext , CXCursor cursor , void * data )
844
863
{
845
864
var fieldName = CXUtil . GetCursorSpelling ( cursor ) ;
@@ -849,10 +868,11 @@ private CppField VisitFieldOrVariable(CppContainerContext containerContext, CXCu
849
868
CppField cppField ;
850
869
// This happen in the type is anonymous, we create implicitly a field for it, but if type is the same
851
870
// 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 ) )
853
872
{
854
873
cppField = previousField ;
855
874
cppField . Name = fieldName ;
875
+ cppField . Type = type ;
856
876
cppField . Offset = cursor . OffsetOfField / 8 ;
857
877
}
858
878
else
0 commit comments