@@ -32,9 +32,9 @@ public override void Populate(TextWriter trapFile)
32
32
trapFile . constructors ( this , Symbol . ContainingType . Name , ContainingType , ( Constructor ) OriginalDefinition ) ;
33
33
trapFile . constructor_location ( this , Location ) ;
34
34
35
- if ( IsPrimary )
35
+ if ( MakeSynthetic )
36
36
{
37
- // Create a synthetic empty body for primary constructors.
37
+ // Create a synthetic empty body for primary and default constructors.
38
38
Statements . SyntheticEmptyBlock . Create ( Context , this , 0 , Location ) ;
39
39
}
40
40
@@ -49,9 +49,9 @@ public override void Populate(TextWriter trapFile)
49
49
protected override void ExtractInitializers ( TextWriter trapFile )
50
50
{
51
51
// Do not extract initializers for constructed types.
52
- // Only extract initializers for constructors with a body and primary constructors.
53
- if ( Block is null && ExpressionBody is null && ! IsPrimary ||
54
- ! IsSourceDeclaration )
52
+ // Extract initializers for constructors with a body, primary constructors
53
+ // and default constructors for classes and structs declared in source code.
54
+ if ( Block is null && ExpressionBody is null && ! MakeSynthetic )
55
55
{
56
56
return ;
57
57
}
@@ -161,6 +161,16 @@ private void ExtractSourceInitializer(TextWriter trapFile, ITypeSymbol? type, IM
161
161
162
162
private bool IsPrimary => PrimaryConstructorSyntax is not null ;
163
163
164
+ // This is a default constructor in a class or struct declared in source.
165
+ private bool IsDefault =>
166
+ Symbol . IsImplicitlyDeclared &&
167
+ Symbol . ContainingType . FromSource ( ) &&
168
+ Symbol . ContainingType . TypeKind is TypeKind . Class or TypeKind . Struct &&
169
+ Symbol . ContainingType . IsSourceDeclaration ( ) &&
170
+ ! Symbol . ContainingType . IsAnonymousType ;
171
+
172
+ private bool MakeSynthetic => IsPrimary || IsDefault ;
173
+
164
174
[ return : NotNullIfNotNull ( nameof ( constructor ) ) ]
165
175
public static new Constructor ? Create ( Context cx , IMethodSymbol ? constructor )
166
176
{
0 commit comments