@@ -2628,11 +2628,21 @@ class TypeChecker {
2628
2628
2629
2629
calculatePropertyType ( ast , env ) {
2630
2630
const type = this . getVariableType ( ast . id , env ) ;
2631
+
2632
+ if ( ! ast . id . inferred ) {
2633
+ ast . id . inferred = type ;
2634
+ }
2635
+
2636
+ if ( ! ast . propertyPathTypes ) {
2637
+ ast . propertyPathTypes = new Array ( ast . propertyPath . length ) ;
2638
+ }
2639
+
2631
2640
if ( type . type === 'model' || type . type === 'map' ) {
2632
2641
let current = type ;
2633
2642
for ( let i = 0 ; i < ast . propertyPath . length ; i ++ ) {
2634
2643
let prop = ast . propertyPath [ i ] ;
2635
2644
current = this . getPropertyType ( current , prop . lexeme ) ;
2645
+ ast . propertyPathTypes [ i ] = current ;
2636
2646
}
2637
2647
2638
2648
return current ;
@@ -3151,11 +3161,17 @@ class TypeChecker {
3151
3161
mainType = this . getVariableType ( ast . left . id , env ) ;
3152
3162
}
3153
3163
3154
- if ( mainType . type === 'array' ) {
3164
+ if ( mainType . type === 'map' ) {
3165
+ if ( ! this . isStringType ( ast . left . accessKey , env ) ) {
3166
+ this . error ( `The key expr type must be string type` , ast . left . accessKey ) ;
3167
+ }
3168
+ } else if ( mainType . type === 'array' ) {
3155
3169
ast . left . type = 'array_access' ;
3156
3170
if ( ! this . isNumberType ( ast . left . accessKey , env ) ) {
3157
- this . error ( `The key expr type must be number type` , ast . accessKey ) ;
3171
+ this . error ( `The key expr type must be number type` , ast . left . accessKey ) ;
3158
3172
}
3173
+ } else {
3174
+ this . error ( `the [] form only support map or array type` , ast . left . accessKey ) ;
3159
3175
}
3160
3176
} else {
3161
3177
throw new Error ( 'unimplemented' ) ;
0 commit comments