]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/gc: simplify typechecking definitions
authorMatthew Dempsky <mdempsky@google.com>
Tue, 16 Oct 2018 18:58:00 +0000 (11:58 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Tue, 16 Oct 2018 20:54:04 +0000 (20:54 +0000)
There are only a handful of nodes that we need to pass to
typecheckdef (OLITERAL, ONAME, OTYPE, and ONONAME), but typecheck1
takes the awkward approach of calling typecheckdef on every node with
Sym != nil, and then excluding a long list of uninteresting Ops that
have a non-nil Sym.

Passes toolstash-check.

Change-Id: I0271d2faff0208ad57ddc1f1a540a5fbed870234
Reviewed-on: https://go-review.googlesource.com/c/142657
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/typecheck.go

index cfdd88d45ebbef0c5599cf851d335fee10148fb9..d2354e47beedb83aa78ef544eb4596c8362a62e6 100644 (file)
@@ -296,21 +296,21 @@ func indexlit(n *Node) *Node {
 //     n.Left = typecheck1(n.Left, top)
 func typecheck1(n *Node, top int) *Node {
        switch n.Op {
-       case OXDOT, ODOT, ODOTPTR, ODOTMETH, ODOTINTER, ORETJMP:
-               // n.Sym is a field/method name, not a variable.
-       default:
-               if n.Sym != nil {
-                       if n.Op == ONAME && n.SubOp() != 0 && top&Ecall == 0 {
-                               yyerror("use of builtin %v not in function call", n.Sym)
-                               n.Type = nil
-                               return n
-                       }
+       case OLITERAL, ONAME, ONONAME, OTYPE:
+               if n.Sym == nil {
+                       break
+               }
 
-                       typecheckdef(n)
-                       if n.Op == ONONAME {
-                               n.Type = nil
-                               return n
-                       }
+               if n.Op == ONAME && n.SubOp() != 0 && top&Ecall == 0 {
+                       yyerror("use of builtin %v not in function call", n.Sym)
+                       n.Type = nil
+                       return n
+               }
+
+               typecheckdef(n)
+               if n.Op == ONONAME {
+                       n.Type = nil
+                       return n
                }
        }
 
@@ -3666,9 +3666,6 @@ func typecheckdef(n *Node) {
        default:
                Fatalf("typecheckdef %v", n.Op)
 
-       case OGOTO, OLABEL, OPACK:
-               // nothing to do here
-
        case OLITERAL:
                if n.Name.Param.Ntype != nil {
                        n.Name.Param.Ntype = typecheck(n.Name.Param.Ntype, Etype)