Skip to content

Commit

Permalink
fix a tuple type error
Browse files Browse the repository at this point in the history
Signed-off-by: Su Yihan <[email protected]>
  • Loading branch information
yviansu committed Feb 21, 2024
1 parent cda461d commit b810e98
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1612,13 +1612,17 @@ export class TypeResolver {
}
} else {
if (ts.isArrayLiteralExpression(parentNode)) {
const parentFieldLength = (<TSTuple>parentType).elements
.length;
for (let i = 0; i < parentFieldLength; i++) {
if (parentNode.elements[i] === node) {
type = (<TSTuple>parentType).elements[i];
break;
if (parentType instanceof TSTuple) {
const parentFieldLength =
parentType.elements.length;
for (let i = 0; i < parentFieldLength; i++) {
if (parentNode.elements[i] === node) {
type = (<TSTuple>parentType).elements[i];
break;
}
}
} else {
type = (<TSArray>parentType).elementType;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/samples/tuple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export function tuple_as_array_elem() {
console.log(array[0][1]);
console.log(array[1][1]);
console.log(array[2][1]);
const iterable: [i64, string][] = [[1, 'value1']];
console.log(iterable[0][0]);
}

export function tuple_as_obj_field() {
Expand Down
2 changes: 1 addition & 1 deletion tools/validate/wamr/validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4209,7 +4209,7 @@
{
"name": "tuple_as_array_elem",
"args": [],
"result": "hi_1\nhi_2\nhi_3"
"result": "hi_1\nhi_2\nhi_3\n1"
},
{
"name": "tuple_as_obj_field",
Expand Down

0 comments on commit b810e98

Please sign in to comment.