@@ -110,40 +110,46 @@ void PerformNameResolution(ASTContextRef context, ASTModuleDeclarationRef module
110
110
}
111
111
}
112
112
113
- for (Index index = 0 ; index < ASTArrayGetElementCount (module -> sourceUnits ); index ++ )
114
- {
113
+ for (Index index = 0 ; index < ASTArrayGetElementCount (module -> sourceUnits ); index ++ ) {
115
114
ASTSourceUnitRef sourceUnit = (ASTSourceUnitRef )ASTArrayGetElementAtIndex (module -> sourceUnits , index );
116
- for (Index sourceUnitIndex = 0 ; sourceUnitIndex < ASTArrayGetElementCount (sourceUnit -> declarations ); sourceUnitIndex ++ )
117
- {
115
+ for (Index sourceUnitIndex = 0 ; sourceUnitIndex < ASTArrayGetElementCount (sourceUnit -> declarations ); sourceUnitIndex ++ ) {
118
116
ASTNodeRef child = (ASTNodeRef )ASTArrayGetElementAtIndex (sourceUnit -> declarations , sourceUnitIndex );
119
- if (child -> tag == ASTTagEnumerationDeclaration )
120
- {
117
+ if (child -> tag == ASTTagEnumerationDeclaration ) {
121
118
ASTEnumerationDeclarationRef enumeration = (ASTEnumerationDeclarationRef )child ;
122
119
_PerformNameResolutionForEnumerationBody (context , enumeration );
123
120
continue ;
124
121
}
125
122
126
- if (child -> tag == ASTTagStructureDeclaration )
127
- {
123
+ if (child -> tag == ASTTagStructureDeclaration ) {
128
124
ASTStructureDeclarationRef structure = (ASTStructureDeclarationRef )child ;
129
125
_PerformNameResolutionForStructureBody (context , structure );
130
126
continue ;
131
127
}
132
128
133
- if (child -> tag == ASTTagValueDeclaration )
134
- {
129
+ if (child -> tag == ASTTagValueDeclaration ) {
135
130
ASTValueDeclarationRef value = (ASTValueDeclarationRef )child ;
131
+ ASTTypeRef Type = ASTNodeGetType (value );
132
+ Bool IsUntyped = ASTTypeIsError (Type ) && ASTNodeHasFlag (value , ASTFlagsIsUntyped );
133
+
134
+ if (IsUntyped && !value -> initializer ) {
135
+ ReportError ("Cannot infer type of declaration" );
136
+ continue ;
137
+ }
138
+
139
+ if (IsUntyped && value -> initializer ) {
140
+ _PerformNameResolutionForExpression (context , value -> initializer , true);
141
+ ASTNodeGetType (value ) = ASTNodeGetType (value -> initializer );
142
+ }
143
+
136
144
_ResolveDeclarationsOfTypeAndSubstituteType (context , value -> base .base .scope , & value -> base .base .type );
137
145
138
- if (value -> initializer )
139
- {
146
+ if (value -> initializer ) {
140
147
value -> initializer -> expectedType = value -> base .base .type ;
141
148
_PerformNameResolutionForExpression (context , value -> initializer , true);
142
149
}
143
150
}
144
151
145
- if (child -> tag == ASTTagTypeAliasDeclaration )
146
- {
152
+ if (child -> tag == ASTTagTypeAliasDeclaration ) {
147
153
ASTTypeAliasDeclarationRef alias = (ASTTypeAliasDeclarationRef )child ;
148
154
_ResolveDeclarationsOfTypeAndSubstituteType (context , alias -> base .base .scope , & alias -> base .base .type );
149
155
}
@@ -571,22 +577,30 @@ static inline void _PerformNameResolutionForNode(ASTContextRef context, ASTNodeR
571
577
ASTValueDeclarationRef value = (ASTValueDeclarationRef )node ;
572
578
assert (value -> kind == ASTValueKindVariable );
573
579
574
- if (_ResolveDeclarationsOfTypeAndSubstituteType (context , value -> base .base .scope , & value -> base .base .type ))
575
- {
580
+ ASTTypeRef Type = ASTNodeGetType (value );
581
+ Bool IsUntyped = ASTTypeIsError (Type ) && ASTNodeHasFlag (value , ASTFlagsIsUntyped );
582
+ if (IsUntyped && !value -> initializer ) {
583
+ ReportError ("Cannot infer type of declaration" );
584
+ break ;
585
+ }
586
+
587
+ if (IsUntyped && value -> initializer ) {
588
+ _PerformNameResolutionForExpression (context , value -> initializer , true);
589
+ ASTNodeGetType (value ) = ASTNodeGetType (value -> initializer );
590
+ }
591
+
592
+ if (_ResolveDeclarationsOfTypeAndSubstituteType (context , value -> base .base .scope , & value -> base .base .type )) {
576
593
SymbolID symbol = SymbolTableLookupSymbol (symbolTable , value -> base .base .scope , value -> base .name );
577
- if (symbol == kSymbolNull )
578
- {
594
+ if (symbol == kSymbolNull ) {
579
595
symbol = SymbolTableInsertSymbol (symbolTable , value -> base .base .scope , value -> base .name );
580
596
SymbolTableSetSymbolDefinition (symbolTable , symbol , value );
581
597
}
582
- else
583
- {
598
+ else {
584
599
ReportError ("Invalid redeclaration of identifier" );
585
600
}
586
601
}
587
602
588
- if (value -> initializer )
589
- {
603
+ if (value -> initializer ) {
590
604
value -> initializer -> expectedType = value -> base .base .type ;
591
605
_PerformNameResolutionForExpression (context , value -> initializer , true);
592
606
}
0 commit comments