Skip to content

Commit cbe15dd

Browse files
committed
fix the prop path
1 parent 5eb242e commit cbe15dd

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/semantic.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -2628,11 +2628,21 @@ class TypeChecker {
26282628

26292629
calculatePropertyType(ast, env) {
26302630
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+
26312640
if (type.type === 'model' || type.type === 'map') {
26322641
let current = type;
26332642
for (let i = 0; i < ast.propertyPath.length; i++) {
26342643
let prop = ast.propertyPath[i];
26352644
current = this.getPropertyType(current, prop.lexeme);
2645+
ast.propertyPathTypes[i] = current;
26362646
}
26372647

26382648
return current;
@@ -3151,11 +3161,17 @@ class TypeChecker {
31513161
mainType = this.getVariableType(ast.left.id, env);
31523162
}
31533163

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') {
31553169
ast.left.type = 'array_access';
31563170
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);
31583172
}
3173+
} else {
3174+
this.error(`the [] form only support map or array type`, ast.left.accessKey);
31593175
}
31603176
} else {
31613177
throw new Error('unimplemented');

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@darabonba/parser",
3-
"version": "2.1.6",
3+
"version": "2.1.7",
44
"main": "index.js",
55
"directories": {
66
"lib": "lib",

0 commit comments

Comments
 (0)