aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/typecheck/typecheck.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2021-01-02 03:15:14 -0800
committerMatthew Dempsky <mdempsky@google.com>2021-01-03 06:16:35 +0000
commit57c426c9a57736d84f6ddd88d7a3306e63f66945 (patch)
treeb38449442fca435139830404e2d0282e95918cc9 /src/cmd/compile/internal/typecheck/typecheck.go
parentb1747756e30a4e1ea0698ddbbb08f5cb7d97b1ba (diff)
downloadgo-57c426c9a57736d84f6ddd88d7a3306e63f66945.tar.gz
go-57c426c9a57736d84f6ddd88d7a3306e63f66945.zip
[dev.regabi] cmd/compile: tighten typecheckdef to *ir.Name
We only actually care about ir.Names in typecheckdef, so don't bother calling it on anything else. Allows us to get rid of some more superfluous .Name() calls and .(*ir.Name) assertions. Passes toolstash -cmp. Change-Id: I78c7cb680178991ea185958b47a36f101d4d5ef7 Reviewed-on: https://go-review.googlesource.com/c/go/+/281004 Trust: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Diffstat (limited to 'src/cmd/compile/internal/typecheck/typecheck.go')
-rw-r--r--src/cmd/compile/internal/typecheck/typecheck.go25
1 files changed, 10 insertions, 15 deletions
diff --git a/src/cmd/compile/internal/typecheck/typecheck.go b/src/cmd/compile/internal/typecheck/typecheck.go
index d0922e8508..812b94de0d 100644
--- a/src/cmd/compile/internal/typecheck/typecheck.go
+++ b/src/cmd/compile/internal/typecheck/typecheck.go
@@ -474,11 +474,8 @@ func indexlit(n ir.Node) ir.Node {
// typecheck1 should ONLY be called from typecheck.
func typecheck1(n ir.Node, top int) ir.Node {
- switch n.Op() {
- case ir.OLITERAL, ir.ONAME, ir.OTYPE:
- if n.Sym() != nil {
- typecheckdef(n)
- }
+ if n, ok := n.(*ir.Name); ok {
+ typecheckdef(n)
}
switch n.Op() {
@@ -1735,7 +1732,7 @@ func typecheckdeftype(n *ir.Name) {
types.ResumeCheckSize()
}
-func typecheckdef(n ir.Node) {
+func typecheckdef(n *ir.Name) {
if base.EnableTrace && base.Flag.LowerT {
defer tracePrint("typecheckdef", n)(nil)
}
@@ -1755,7 +1752,7 @@ func typecheckdef(n ir.Node) {
}
lno := ir.SetPos(n)
- typecheckdefstack = append(typecheckdefstack, n.(*ir.Name))
+ typecheckdefstack = append(typecheckdefstack, n)
if n.Walkdef() == 2 {
base.FlushErrors()
fmt.Printf("typecheckdef loop:")
@@ -1774,18 +1771,18 @@ func typecheckdef(n ir.Node) {
base.Fatalf("typecheckdef %v", n.Op())
case ir.OLITERAL:
- if n.Name().Ntype != nil {
- n.Name().Ntype = typecheckNtype(n.Name().Ntype)
- n.SetType(n.Name().Ntype.Type())
- n.Name().Ntype = nil
+ if n.Ntype != nil {
+ n.Ntype = typecheckNtype(n.Ntype)
+ n.SetType(n.Ntype.Type())
+ n.Ntype = nil
if n.Type() == nil {
n.SetDiag(true)
goto ret
}
}
- e := n.Name().Defn
- n.Name().Defn = nil
+ e := n.Defn
+ n.Defn = nil
if e == nil {
ir.Dump("typecheckdef nil defn", n)
base.ErrorfAt(n.Pos(), "xxx")
@@ -1828,7 +1825,6 @@ func typecheckdef(n ir.Node) {
}
case ir.ONAME:
- n := n.(*ir.Name)
if n.Ntype != nil {
n.Ntype = typecheckNtype(n.Ntype)
n.SetType(n.Ntype.Type())
@@ -1865,7 +1861,6 @@ func typecheckdef(n ir.Node) {
n.Defn = Stmt(n.Defn) // fills in n.Type
case ir.OTYPE:
- n := n.(*ir.Name)
if n.Alias() {
// Type alias declaration: Simply use the rhs type - no need
// to create a new type.