• Alberto Donizetti's avatar
    cmd/compile: fix OTYPESW Op comment · 07f7db3e
    Alberto Donizetti authored
    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/69112Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
    07f7db3e
Name
Last commit
Last update
.github Loading commit data...
api Loading commit data...
doc Loading commit data...
lib/time Loading commit data...
misc Loading commit data...
src Loading commit data...
test Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
AUTHORS Loading commit data...
CONTRIBUTING.md Loading commit data...
CONTRIBUTORS Loading commit data...
LICENSE Loading commit data...
PATENTS Loading commit data...
README.md Loading commit data...
favicon.ico Loading commit data...
robots.txt Loading commit data...