[dev.typeparams] cmd/compile: handle ONONAME in subster.node

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>
This commit is contained in:
Cuong Manh Le 2021-06-01 00:56:14 +07:00
parent f32f4f58d9
commit 4b10e4c547
2 changed files with 23 additions and 0 deletions

View 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

View file

@ -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")
}