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: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 39fa301b
......@@ -296,10 +296,11 @@ 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 {
case OLITERAL, ONAME, ONONAME, OTYPE:
if n.Sym == nil {
break
}
if n.Op == ONAME && n.SubOp() != 0 && top&Ecall == 0 {
yyerror("use of builtin %v not in function call", n.Sym)
n.Type = nil
......@@ -312,7 +313,6 @@ func typecheck1(n *Node, top int) *Node {
return n
}
}
}
ok := 0
switch n.Op {
......@@ -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)
......
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