@@ -39,80 +39,78 @@ protected override void ExtractInitializers(TextWriter trapFile)
39
39
var syntax = Syntax ;
40
40
var initializer = syntax ? . Initializer ;
41
41
42
- if ( initializer is null )
42
+ if ( initializer is not null )
43
43
{
44
- if ( Symbol . MethodKind is MethodKind . Constructor )
44
+ ITypeSymbol initializerType ;
45
+ var symbolInfo = Context . GetSymbolInfo ( initializer ) ;
46
+
47
+ switch ( initializer . Kind ( ) )
45
48
{
46
- var baseType = Symbol . ContainingType . BaseType ;
47
- if ( baseType is null )
48
- {
49
- if ( Symbol . ContainingType . SpecialType != SpecialType . System_Object )
50
- {
51
- Context . ModelError ( Symbol , "Unable to resolve base type in implicit constructor initializer" ) ;
52
- }
49
+ case SyntaxKind . BaseConstructorInitializer :
50
+ initializerType = Symbol . ContainingType . BaseType ! ;
51
+ break ;
52
+ case SyntaxKind . ThisConstructorInitializer :
53
+ initializerType = Symbol . ContainingType ;
54
+ break ;
55
+ default :
56
+ Context . ModelError ( initializer , "Unknown initializer" ) ;
53
57
return ;
54
- }
58
+ }
55
59
56
- var baseConstructor = baseType . InstanceConstructors . FirstOrDefault ( c => c . Arity is 0 ) ;
60
+ var initInfo = new ExpressionInfo ( Context ,
61
+ AnnotatedTypeSymbol . CreateNotAnnotated ( initializerType ) ,
62
+ Context . CreateLocation ( initializer . ThisOrBaseKeyword . GetLocation ( ) ) ,
63
+ Kinds . ExprKind . CONSTRUCTOR_INIT ,
64
+ this ,
65
+ - 1 ,
66
+ false ,
67
+ null ) ;
57
68
58
- if ( baseConstructor is null )
59
- {
60
- Context . ModelError ( Symbol , "Unable to resolve implicit constructor initializer call" ) ;
61
- return ;
62
- }
69
+ var init = new Expression ( initInfo ) ;
63
70
64
- var baseConstructorTarget = Create ( Context , baseConstructor ) ;
65
- var info = new ExpressionInfo ( Context ,
66
- AnnotatedTypeSymbol . CreateNotAnnotated ( baseType ) ,
67
- Location ,
68
- Kinds . ExprKind . CONSTRUCTOR_INIT ,
69
- this ,
70
- - 1 ,
71
- isCompilerGenerated : true ,
72
- null ) ;
73
-
74
- trapFile . expr_call ( new Expression ( info ) , baseConstructorTarget ) ;
71
+ var target = Constructor . Create ( Context , ( IMethodSymbol ? ) symbolInfo . Symbol ) ;
72
+ if ( target is null )
73
+ {
74
+ Context . ModelError ( Symbol , "Unable to resolve call" ) ;
75
+ return ;
75
76
}
76
- return ;
77
- }
78
77
79
- ITypeSymbol initializerType ;
80
- var symbolInfo = Context . GetSymbolInfo ( initializer ) ;
78
+ trapFile . expr_call ( init , target ) ;
81
79
82
- switch ( initializer . Kind ( ) )
80
+ init . PopulateArguments ( trapFile , initializer . ArgumentList , 0 ) ;
81
+ }
82
+ else if ( Symbol . MethodKind is MethodKind . Constructor )
83
83
{
84
- case SyntaxKind . BaseConstructorInitializer :
85
- initializerType = Symbol . ContainingType . BaseType ! ;
86
- break ;
87
- case SyntaxKind . ThisConstructorInitializer :
88
- initializerType = Symbol . ContainingType ;
89
- break ;
90
- default :
91
- Context . ModelError ( initializer , "Unknown initializer" ) ;
84
+ var baseType = Symbol . ContainingType . BaseType ;
85
+ if ( baseType is null )
86
+ {
87
+ if ( Symbol . ContainingType . SpecialType != SpecialType . System_Object )
88
+ {
89
+ Context . ModelError ( Symbol , "Unable to resolve base type in implicit constructor initializer" ) ;
90
+ }
92
91
return ;
93
- }
92
+ }
94
93
95
- var initInfo = new ExpressionInfo ( Context ,
96
- AnnotatedTypeSymbol . CreateNotAnnotated ( initializerType ) ,
97
- Context . CreateLocation ( initializer . ThisOrBaseKeyword . GetLocation ( ) ) ,
98
- Kinds . ExprKind . CONSTRUCTOR_INIT ,
99
- this ,
100
- - 1 ,
101
- false ,
102
- null ) ;
94
+ var baseConstructor = baseType . InstanceConstructors . FirstOrDefault ( c => c . Arity is 0 ) ;
103
95
104
- var init = new Expression ( initInfo ) ;
96
+ if ( baseConstructor is null )
97
+ {
98
+ Context . ModelError ( Symbol , "Unable to resolve implicit constructor initializer call" ) ;
99
+ return ;
100
+ }
105
101
106
- var target = Constructor . Create ( Context , ( IMethodSymbol ? ) symbolInfo . Symbol ) ;
107
- if ( target is null )
108
- {
109
- Context . ModelError ( Symbol , "Unable to resolve call" ) ;
110
- return ;
102
+ var baseConstructorTarget = Create ( Context , baseConstructor ) ;
103
+ var info = new ExpressionInfo ( Context ,
104
+ AnnotatedTypeSymbol . CreateNotAnnotated ( baseType ) ,
105
+ Location ,
106
+ Kinds . ExprKind . CONSTRUCTOR_INIT ,
107
+ this ,
108
+ - 1 ,
109
+ isCompilerGenerated : true ,
110
+ null ) ;
111
+
112
+ trapFile . expr_call ( new Expression ( info ) , baseConstructorTarget ) ;
111
113
}
112
-
113
- trapFile . expr_call ( init , target ) ;
114
-
115
- init . PopulateArguments ( trapFile , initializer . ArgumentList , 0 ) ;
116
114
}
117
115
118
116
private ConstructorDeclarationSyntax ? Syntax
0 commit comments