@@ -39,80 +39,78 @@ protected override void ExtractInitializers(TextWriter trapFile)
3939 var syntax = Syntax ;
4040 var initializer = syntax ? . Initializer ;
4141
42- if ( initializer is null )
42+ if ( initializer is not null )
4343 {
44- if ( Symbol . MethodKind is MethodKind . Constructor )
44+ ITypeSymbol initializerType ;
45+ var symbolInfo = Context . GetSymbolInfo ( initializer ) ;
46+
47+ switch ( initializer . Kind ( ) )
4548 {
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" ) ;
5357 return ;
54- }
58+ }
5559
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 ) ;
5768
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 ) ;
6370
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 ;
7576 }
76- return ;
77- }
7877
79- ITypeSymbol initializerType ;
80- var symbolInfo = Context . GetSymbolInfo ( initializer ) ;
78+ trapFile . expr_call ( init , target ) ;
8179
82- switch ( initializer . Kind ( ) )
80+ init . PopulateArguments ( trapFile , initializer . ArgumentList , 0 ) ;
81+ }
82+ else if ( Symbol . MethodKind is MethodKind . Constructor )
8383 {
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+ }
9291 return ;
93- }
92+ }
9493
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 ) ;
10395
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+ }
105101
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 ) ;
111113 }
112-
113- trapFile . expr_call ( init , target ) ;
114-
115- init . PopulateArguments ( trapFile , initializer . ArgumentList , 0 ) ;
116114 }
117115
118116 private ConstructorDeclarationSyntax ? Syntax
0 commit comments