mirror of
https://github.com/golang/go
synced 2024-09-30 02:24:43 -06:00
go/types, types2: skip comparison for operands with invalid types
Fixes #54405. Change-Id: Ia7b2709b83966fa080e41e3d4818527d1e8b49f9 Reviewed-on: https://go-review.googlesource.com/c/go/+/424054 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com> Auto-Submit: Robert Griesemer <gri@google.com>
This commit is contained in:
parent
e3c2e4cb7d
commit
7ec0ec3645
@ -783,6 +783,12 @@ func (check *Checker) implicitTypeAndValue(x *operand, target Type) (Type, const
|
||||
|
||||
// If switchCase is true, the operator op is ignored.
|
||||
func (check *Checker) comparison(x, y *operand, op syntax.Operator, switchCase bool) {
|
||||
// Avoid spurious errors if any of the operands has an invalid type (issue #54405).
|
||||
if x.typ == Typ[Invalid] || y.typ == Typ[Invalid] {
|
||||
x.mode = invalid
|
||||
return
|
||||
}
|
||||
|
||||
if switchCase {
|
||||
op = syntax.Eql
|
||||
}
|
||||
|
16
src/cmd/compile/internal/types2/testdata/fixedbugs/issue54405.go
vendored
Normal file
16
src/cmd/compile/internal/types2/testdata/fixedbugs/issue54405.go
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Test that we don't see spurious errors for ==
|
||||
// for values with invalid types due to prior errors.
|
||||
|
||||
package p
|
||||
|
||||
var x struct {
|
||||
f *NotAType /* ERROR undeclared name */
|
||||
}
|
||||
var _ = x.f == nil // no error expected here
|
||||
|
||||
var y *NotAType /* ERROR undeclared name */
|
||||
var _ = y == nil // no error expected here
|
@ -736,6 +736,12 @@ func (check *Checker) implicitTypeAndValue(x *operand, target Type) (Type, const
|
||||
|
||||
// If switchCase is true, the operator op is ignored.
|
||||
func (check *Checker) comparison(x, y *operand, op token.Token, switchCase bool) {
|
||||
// Avoid spurious errors if any of the operands has an invalid type (issue #54405).
|
||||
if x.typ == Typ[Invalid] || y.typ == Typ[Invalid] {
|
||||
x.mode = invalid
|
||||
return
|
||||
}
|
||||
|
||||
if switchCase {
|
||||
op = token.EQL
|
||||
}
|
||||
|
16
src/go/types/testdata/fixedbugs/issue54405.go
vendored
Normal file
16
src/go/types/testdata/fixedbugs/issue54405.go
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
// Copyright 2022 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Test that we don't see spurious errors for ==
|
||||
// for values with invalid types due to prior errors.
|
||||
|
||||
package p
|
||||
|
||||
var x struct {
|
||||
f *NotAType /* ERROR undeclared name */
|
||||
}
|
||||
var _ = x.f == nil // no error expected here
|
||||
|
||||
var y *NotAType /* ERROR undeclared name */
|
||||
var _ = y == nil // no error expected here
|
Loading…
Reference in New Issue
Block a user