]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile: handle ONONAME in subster.node
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 31 May 2021 17:56:14 +0000 (00:56 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 1 Jun 2021 17:10:20 +0000 (17:10 +0000)
Fixes #46472

Change-Id: I27802978fa0c3bb32a29e452165a6fcac93473bb
Reviewed-on: https://go-review.googlesource.com/c/go/+/323731
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: Dan Scales <danscales@google.com>
src/cmd/compile/internal/noder/stencil.go
test/typeparam/issue46472.go [new file with mode: 0644]

index e273a80b20ffbc7b2f63ff82422705787e16c81e..36a6f2e6d029325fecb3ca08dd0e3fcdde3d9a21 100644 (file)
@@ -350,6 +350,9 @@ func (subst *subster) node(n ir.Node) ir.Node {
                                return v
                        }
                        return x
+               case ir.ONONAME:
+                       // This handles the identifier in a type switch guard
+                       fallthrough
                case ir.OLITERAL, ir.ONIL:
                        if x.Sym() != nil {
                                return x
diff --git a/test/typeparam/issue46472.go b/test/typeparam/issue46472.go
new file mode 100644 (file)
index 0000000..bab48e7
--- /dev/null
@@ -0,0 +1,20 @@
+// run -gcflags=-G=3
+
+// Copyright 2021 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.
+
+package main
+
+func foo[T any](d T) {
+       switch v := interface{}(d).(type) {
+       case string:
+               if v != "x" {
+                       panic("unexpected v: "+v)
+               }
+       }
+
+}
+func main() {
+       foo("x")
+}