Improve type checker

This commit is contained in:
Anton Medvedev
2023-08-17 23:39:35 +02:00
parent 2fa8105b01
commit 7ad2645777
2 changed files with 12 additions and 1 deletions
+7 -1
View File
@@ -321,9 +321,15 @@ func (v *visitor) BinaryNode(node *ast.BinaryNode) (reflect.Type, info) {
return boolType, info{}
}
if isMap(r) {
if l == nil {
return v.error(node, "cannot use nil as map key")
}
if !isAny(l) && !l.AssignableTo(r.Key()) {
return v.error(node, "cannot use %v (type %v) as type %v in map key", l, l, r.Key())
}
return boolType, info{}
}
if isArray(r) {
if isInteger(l) && isArray(r) {
return boolType, info{}
}
if isAny(l) && anyOf(r, isString, isArray, isMap) {
+5
View File
@@ -489,6 +489,11 @@ FuncTyped(42)
cannot use int as argument (type string) to call FuncTyped (1:11)
| FuncTyped(42)
| ..........^
.0 in MapOfFoo
cannot use float64 (type float64) as type string in map key (1:4)
| .0 in MapOfFoo
| ...^
`
func TestCheck_error(t *testing.T) {