Skip to content

Commit

Permalink
interp: improve type checking when comparing aliased types
Browse files Browse the repository at this point in the history
Fixes #1421.
  • Loading branch information
RussellLuo committed Jun 30, 2022
1 parent f76db27 commit cb642c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions _test/issue-1421.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

type Number = int

func main() {
println(Number(1) < int(2))
}

// Output: true
2 changes: 1 addition & 1 deletion interp/typecheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (check typecheck) comparison(n *node) error {

ok := false

if !isInterface(t0) && !isInterface(t1) && !t0.isNil() && !t1.isNil() && t0.untyped == t1.untyped && t0.id() != t1.id() {
if !isInterface(t0) && !isInterface(t1) && !t0.isNil() && !t1.isNil() && t0.untyped == t1.untyped && t0.id() != t1.id() && !typeDefined(t0, t1) {
// Non interface types must be really equals.
return n.cfgErrorf("invalid operation: mismatched types %s and %s", t0.id(), t1.id())
}
Expand Down

0 comments on commit cb642c4

Please sign in to comment.