From 62c52a5ee19279a2151bdf178eee11b95c188a91 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Tue, 16 Oct 2018 11:58:00 -0700 Subject: [PATCH] cmd/compile/internal/gc: simplify typechecking definitions 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 TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/compile/internal/gc/typecheck.go | 31 +++++++++++------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index cfdd88d45e..d2354e47be 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -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) -- 2.48.1