Skip to content

Commit 07f7db3

Browse files
committed
cmd/compile: fix OTYPESW Op comment
OTYPESW Op comment says // List = Left.(type) this seems to be wrong. Adding fmt.Printf("n: %v\n", cond) fmt.Printf(" n.List: %v\n", cond.List) fmt.Printf(" n.Left: %v\n", cond.Left) fmt.Printf(" n.Right: %v\n", cond.Right) to (s *typeSwitch) walk(sw *Node), and compiling the following code snippet var y interface{} switch x := y.(type) { default: println(x) } prints n: <node TYPESW> n.List: n.Left: x n.Right: y The correct OTYPESW Node field positions are // Left = Right.(type) This is confirmed by the fact that, further in the code, typeSwitch.walk() checks that Right (and not Left) is of type interface: cond.Right = walkexpr(cond.Right, &sw.Ninit) if !cond.Right.Type.IsInterface() { yyerror("type switch must be on an interface") return } This patch fixes the OTYPESW comment. Change-Id: Ief1e409cfabb7640d7f7b0d4faabbcffaf605450 Reviewed-on: https://go-review.googlesource.com/69112 Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 0c53b4e commit 07f7db3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/cmd/compile/internal/gc/syntax.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ const (
571571
ORETURN // return List
572572
OSELECT // select { List } (List is list of OXCASE or OCASE)
573573
OSWITCH // switch Ninit; Left { List } (List is a list of OXCASE or OCASE)
574-
OTYPESW // List = Left.(type) (appears as .Left of OSWITCH)
574+
OTYPESW // Left = Right.(type) (appears as .Left of OSWITCH)
575575

576576
// types
577577
OTCHAN // chan int

0 commit comments

Comments
 (0)