@@ -28,11 +28,32 @@ public static NamedType Create(Context cx, INamedTypeSymbol type) =>
28
28
public static NamedType CreateNamedTypeFromTupleType ( Context cx , INamedTypeSymbol type ) =>
29
29
UnderlyingTupleTypeFactory . Instance . CreateEntity ( cx , ( new SymbolEqualityWrapper ( type ) , typeof ( TupleType ) ) , type ) ;
30
30
31
- public override bool NeedsPopulation => base . NeedsPopulation || Symbol . TypeKind == TypeKind . Error ;
31
+ public override bool NeedsPopulation => base . NeedsPopulation || IsBrokenType ( Symbol ) ;
32
+
33
+ /// <summary>
34
+ /// Returns true in case we suspect this is broken type.
35
+ /// </summary>
36
+ /// <param name="symbol">Type symbol</param>
37
+ private bool IsBrokenType ( ITypeSymbol symbol )
38
+ {
39
+ if ( symbol . TypeKind == TypeKind . Error )
40
+ {
41
+ return true ;
42
+ }
43
+
44
+ if ( ! Context . ExtractionContext . IsStandalone )
45
+ {
46
+ return false ;
47
+ }
48
+ // (1) public class { ... } is a broken type and doesn't have a name.
49
+ // (2) public class var { ... } is a an allowed type, but it overrides the var keyword for all uses.
50
+ // It is probably a better heuristic to treat it as a broken type.
51
+ return string . IsNullOrEmpty ( symbol . Name ) || symbol . Name == "var" ;
52
+ }
32
53
33
54
public override void Populate ( TextWriter trapFile )
34
55
{
35
- if ( Symbol . TypeKind == TypeKind . Error )
56
+ if ( IsBrokenType ( Symbol ) )
36
57
{
37
58
UnknownType . Create ( Context ) ; // make sure this exists so we can use it in `TypeRef::getReferencedType`
38
59
Context . ExtractionContext . MissingType ( Symbol . ToString ( ) ! , Context . FromSource ) ;
@@ -166,7 +187,9 @@ private class UnderlyingTupleTypeFactory : CachedEntityFactory<INamedTypeSymbol,
166
187
// Create typerefs for constructed error types in case they are fully defined elsewhere.
167
188
// We cannot use `!this.NeedsPopulation` because this would not be stable as it would depend on
168
189
// the assembly that was being extracted at the time.
169
- private bool UsesTypeRef => Symbol . TypeKind == TypeKind . Error || SymbolEqualityComparer . Default . Equals ( Symbol . OriginalDefinition , Symbol ) ;
190
+ private bool UsesTypeRef =>
191
+ IsBrokenType ( Symbol ) ||
192
+ SymbolEqualityComparer . Default . Equals ( Symbol . OriginalDefinition , Symbol ) ;
170
193
171
194
public override Type TypeRef => UsesTypeRef ? ( Type ) NamedTypeRef . Create ( Context , Symbol ) : this ;
172
195
}
0 commit comments