Commit 62c52a5e authored by Matthew Dempsky's avatar Matthew Dempsky

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 <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 39fa301b
...@@ -296,21 +296,21 @@ func indexlit(n *Node) *Node { ...@@ -296,21 +296,21 @@ func indexlit(n *Node) *Node {
// n.Left = typecheck1(n.Left, top) // n.Left = typecheck1(n.Left, top)
func typecheck1(n *Node, top int) *Node { func typecheck1(n *Node, top int) *Node {
switch n.Op { switch n.Op {
case OXDOT, ODOT, ODOTPTR, ODOTMETH, ODOTINTER, ORETJMP: case OLITERAL, ONAME, ONONAME, OTYPE:
// n.Sym is a field/method name, not a variable. if n.Sym == nil {
default: break
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
}
typecheckdef(n) if n.Op == ONAME && n.SubOp() != 0 && top&Ecall == 0 {
if n.Op == ONONAME { yyerror("use of builtin %v not in function call", n.Sym)
n.Type = nil n.Type = nil
return n return n
} }
typecheckdef(n)
if n.Op == ONONAME {
n.Type = nil
return n
} }
} }
...@@ -3666,9 +3666,6 @@ func typecheckdef(n *Node) { ...@@ -3666,9 +3666,6 @@ func typecheckdef(n *Node) {
default: default:
Fatalf("typecheckdef %v", n.Op) Fatalf("typecheckdef %v", n.Op)
case OGOTO, OLABEL, OPACK:
// nothing to do here
case OLITERAL: case OLITERAL:
if n.Name.Param.Ntype != nil { if n.Name.Param.Ntype != nil {
n.Name.Param.Ntype = typecheck(n.Name.Param.Ntype, Etype) n.Name.Param.Ntype = typecheck(n.Name.Param.Ntype, Etype)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment