Skip to content

Commit

Permalink
Remove redundant operator override check
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Feb 17, 2024
1 parent 8ecb18a commit 95084fb
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 32 deletions.
8 changes: 0 additions & 8 deletions checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,6 @@ func (v *checker) BinaryNode(node *ast.BinaryNode) (reflect.Type, info) {
l = deref.Type(l)
r = deref.Type(r)

// check operator overloading
if fns, ok := v.config.Operators[node.Operator]; ok {
t, _, ok := conf.FindSuitableOperatorOverload(fns, v.config.Types, v.config.Functions, l, r)
if ok {
return t, info{}
}
}

switch node.Operator {
case "==", "!=":
if isComparable(l, r) {
Expand Down
24 changes: 0 additions & 24 deletions checker/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,30 +714,6 @@ func TestCheck_AllowUndefinedVariables_OptionalChaining(t *testing.T) {
assert.NoError(t, err)
}

func TestCheck_OperatorOverload(t *testing.T) {
type Date struct{}
env := map[string]any{
"a": Date{},
"b": Date{},
"add": func(a, b Date) bool {
return true
},
}
tree, err := parser.Parse(`a + b`)
require.NoError(t, err)

config := conf.New(env)
expr.AsBool()(config)

_, err = checker.Check(tree, config)
require.Error(t, err)
require.Contains(t, err.Error(), "invalid operation: + (mismatched types checker_test.Date and checker_test.Date)")

expr.Operator("+", "add")(config)
_, err = checker.Check(tree, config)
require.NoError(t, err)
}

func TestCheck_PointerNode(t *testing.T) {
_, err := checker.Check(&parser.Tree{Node: &ast.PointerNode{}}, nil)
assert.Error(t, err)
Expand Down

0 comments on commit 95084fb

Please sign in to comment.