From: Cuong Manh Le Date: Mon, 31 May 2021 17:56:14 +0000 (+0700) Subject: [dev.typeparams] cmd/compile: handle ONONAME in subster.node X-Git-Tag: go1.18beta1~1818^2^2~468 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=4b10e4c547;p=gostls13.git [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 Run-TryBot: Cuong Manh Le TryBot-Result: Go Bot Reviewed-by: Dan Scales --- diff --git a/src/cmd/compile/internal/noder/stencil.go b/src/cmd/compile/internal/noder/stencil.go index e273a80b20..36a6f2e6d0 100644 --- a/src/cmd/compile/internal/noder/stencil.go +++ b/src/cmd/compile/internal/noder/stencil.go @@ -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 index 0000000000..bab48e7d2f --- /dev/null +++ b/test/typeparam/issue46472.go @@ -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") +}