Reject "x == 0" for pointer-typed x

This commit is contained in:
Nigel Tao committed 2018-07-15 16:08:02 +10:00
1 parent fbec79df76
commit fdf152f8b3
1 file changed
+14 -11
+14 -11
View File
@@ -736,17 +736,6 @@ func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error {
rTyp := rhs.MType()
switch op {
default:
if !lTyp.IsNumTypeOrIdeal() {
return fmt.Errorf("check: binary %q: %q, of type %q, does not have a numeric type",
op.AmbiguousForm().Str(q.tm), lhs.Str(q.tm), lTyp.Str(q.tm))
}
if !rTyp.IsNumTypeOrIdeal() {
return fmt.Errorf("check: binary %q: %q, of type %q, does not have a numeric type",
op.AmbiguousForm().Str(q.tm), rhs.Str(q.tm), rTyp.Str(q.tm))
}
case t.IDXBinaryNotEq, t.IDXBinaryEqEq:
// No-op.
case t.IDXBinaryAnd, t.IDXBinaryOr:
if !lTyp.IsBool() {
return fmt.Errorf("check: binary %q: %q, of type %q, does not have a boolean type",
@@ -756,6 +745,20 @@ func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error {
return fmt.Errorf("check: binary %q: %q, of type %q, does not have a boolean type",
op.AmbiguousForm().Str(q.tm), rhs.Str(q.tm), rTyp.Str(q.tm))
}
case t.IDXBinaryNotEq, t.IDXBinaryEqEq:
if lTyp.Eq(typeExprStatus) && rTyp.Eq(typeExprStatus) {
break
}
fallthrough
default:
if !lTyp.IsNumTypeOrIdeal() {
return fmt.Errorf("check: binary %q: %q, of type %q, does not have a numeric type",
op.AmbiguousForm().Str(q.tm), lhs.Str(q.tm), lTyp.Str(q.tm))
}
if !rTyp.IsNumTypeOrIdeal() {
return fmt.Errorf("check: binary %q: %q, of type %q, does not have a numeric type",
op.AmbiguousForm().Str(q.tm), rhs.Str(q.tm), rTyp.Str(q.tm))
}
}
switch op {