From: Cuong Manh Le Date: Thu, 4 Mar 2021 13:56:01 +0000 (+0700) Subject: cmd/compile: do not set type for OTYPESW X-Git-Tag: go1.17beta1~1256 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=51d8d351c1;p=gostls13.git 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 Run-TryBot: Cuong Manh Le TryBot-Result: Go Bot Reviewed-by: Matthew Dempsky --- diff --git a/src/cmd/compile/internal/typecheck/typecheck.go b/src/cmd/compile/internal/typecheck/typecheck.go index 030158b1a1..647465af4f 100644 --- a/src/cmd/compile/internal/typecheck/typecheck.go +++ b/src/cmd/compile/internal/typecheck/typecheck.go @@ -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: diff --git a/test/fixedbugs/issue24470.go b/test/fixedbugs/issue24470.go index 2805998cca..5b7b2b5adf 100644 --- a/test/fixedbugs/issue24470.go +++ b/test/fixedbugs/issue24470.go @@ -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 } }