mirror of
https://github.com/hanzoai/expr.git
synced 2026-09-24 16:58:58 +00:00
Improve type checker
This commit is contained in:
+7
-1
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user