cmd/compile: do not set type for OTYPESW

Same as CL 294031, but for OTYPESW.

Updates #43311

Change-Id: I996f5938835baff1d830c17ed75652315106bdfd
Reviewed-on: https://go-review.googlesource.com/c/go/+/298712
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Cuong Manh Le 2021-03-04 20:56:01 +07:00
parent 80098ef00c
commit 51d8d351c1
2 changed files with 3 additions and 3 deletions

View File

@ -876,7 +876,7 @@ func typecheck1(n ir.Node, top int) ir.Node {
case ir.OTYPESW:
n := n.(*ir.TypeSwitchGuard)
base.Errorf("use of .(type) outside type switch")
n.SetType(nil)
n.SetDiag(true)
return n
case ir.ODCLFUNC:

View File

@ -1,4 +1,4 @@
// errorcheck
// errorcheck -d=panic
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
@ -10,7 +10,7 @@
package p
func f(i interface{}) {
if x, ok := i.(type); ok { // ERROR "outside type switch"
if x, ok := i.(type); ok { // ERROR "assignment mismatch|outside type switch"
_ = x
}
}