Skip to content

Commit

Permalink
[dev.typeparams] cmd/compile: handle ONONAME in subster.node
Browse files Browse the repository at this point in the history
Fixes #46472

Change-Id: I27802978fa0c3bb32a29e452165a6fcac93473bb
Reviewed-on: https://go-review.googlesource.com/c/go/+/323731
Trust: Cuong Manh Le <[email protected]>
Run-TryBot: Cuong Manh Le <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Dan Scales <[email protected]>
  • Loading branch information
cuonglm committed Jun 1, 2021
1 parent f32f4f5 commit 4b10e4c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cmd/compile/internal/noder/stencil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions test/typeparam/issue46472.go
Original file line number Diff line number Diff line change
@@ -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")
}

0 comments on commit 4b10e4c

Please sign in to comment.