mirror of
https://github.com/golang/go
synced 2024-11-16 22:14:45 -07:00
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: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
39fa301bdc
commit
62c52a5ee1
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user