]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: do not set type for OTYPESW
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Thu, 4 Mar 2021 13:56:01 +0000 (20:56 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Fri, 5 Mar 2021 18:46:36 +0000 (18:46 +0000)
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>
src/cmd/compile/internal/typecheck/typecheck.go
test/fixedbugs/issue24470.go

index 030158b1a125360e3fb2dea09d6f92bb79310faa..647465af4fe0f2c3bd0b35d00c3d3be3298b269e 100644 (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:
index 2805998cca57bb5430cf3fb25cb4085761a98723..5b7b2b5adf2b534f1be6b1adeaec8ae295788c19 100644 (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
        }
 }