Skip to content

Commit 8076723

Browse files
committed
Add SequenceNode to type checker
1 parent 3df78d9 commit 8076723

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

checker/checker.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ func (v *checker) visit(node ast.Node) Nature {
178178
nt = v.PointerNode(n)
179179
case *ast.VariableDeclaratorNode:
180180
nt = v.VariableDeclaratorNode(n)
181+
case *ast.SequenceNode:
182+
nt = v.SequenceNode(n)
181183
case *ast.ConditionalNode:
182184
nt = v.ConditionalNode(n)
183185
case *ast.ArrayNode:
@@ -1181,6 +1183,17 @@ func (v *checker) VariableDeclaratorNode(node *ast.VariableDeclaratorNode) Natur
11811183
return exprNature
11821184
}
11831185

1186+
func (v *checker) SequenceNode(node *ast.SequenceNode) Nature {
1187+
if len(node.Nodes) == 0 {
1188+
return v.error(node, "empty sequence expression")
1189+
}
1190+
var last Nature
1191+
for _, node := range node.Nodes {
1192+
last = v.visit(node)
1193+
}
1194+
return last
1195+
}
1196+
11841197
func (v *checker) lookupVariable(name string) (varScope, bool) {
11851198
for i := len(v.varScopes) - 1; i >= 0; i-- {
11861199
if v.varScopes[i].name == name {

checker/checker_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,14 @@ invalid operation: == (mismatched types int and string) (1:33)
669669
invalid operation: > (mismatched types string and int) (1:30)
670670
| 1..3 | map("str") | filter(# > 1)
671671
| .............................^
672+
`,
673+
},
674+
{
675+
`1; 2 + true; 3`,
676+
`
677+
invalid operation: + (mismatched types int and bool) (1:6)
678+
| 1; 2 + true; 3
679+
| .....^
672680
`,
673681
},
674682
}

0 commit comments

Comments
 (0)