aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/typecheck/typecheck.go
diff options
context:
space:
mode:
authorDan Scales <danscales@google.com>2021-03-18 14:36:39 -0700
committerDan Scales <danscales@google.com>2021-03-23 04:23:52 +0000
commit0265b6475f08f2c23a742132db87c357fcbfa458 (patch)
treee436cb1c782b16ab3270c2d11f77765afdd9aa97 /src/cmd/compile/internal/typecheck/typecheck.go
parentb8371d495bb291f61e4fa3ac1b84116c70ac1223 (diff)
downloadgo-0265b6475f08f2c23a742132db87c357fcbfa458.tar.gz
go-0265b6475f08f2c23a742132db87c357fcbfa458.zip
cmd/compile: replace calls to typecheck with transform functions
For additions, compares, and slices, create transform functions that do just the transformations for those nodes by the typecheck package (given that the code has been fully typechecked by types2). For nodes that have no args with typeparams, we call these transform functions directly in noder2. But for nodes that have args with typeparams, we have to delay and call the tranform functions during stenciling, since we don't know the specific types involved. We indicate that a node still needs transformation by setting Typecheck to a new value 3. This value means the current type of the node has been set (via types2), but the node may still need transformation. Had to export typcheck.IsCmp and typecheck.Assignop from the typecheck package. Added new tests list2.go (required delaying compare typecheck/transform because of != compare in checkList) and adder.go (requires delaying add typecheck/transform, since it can do addition for numbers or strings). There are several more transformation functions needed for expressions (indexing, calls, etc.) and several more complicated ones needed for statements (mainly various kinds of assignments). Change-Id: I7d89d13a4108308ea0304a4b815ab60b40c59b0a Reviewed-on: https://go-review.googlesource.com/c/go/+/303091 Run-TryBot: Dan Scales <danscales@google.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Dan Scales <danscales@google.com> Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/typecheck/typecheck.go')
-rw-r--r--src/cmd/compile/internal/typecheck/typecheck.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/typecheck/typecheck.go b/src/cmd/compile/internal/typecheck/typecheck.go
index 30632ac18b..f06a8623d0 100644
--- a/src/cmd/compile/internal/typecheck/typecheck.go
+++ b/src/cmd/compile/internal/typecheck/typecheck.go
@@ -297,7 +297,7 @@ func typecheck(n ir.Node, top int) (res ir.Node) {
// Skip typecheck if already done.
// But re-typecheck ONAME/OTYPE/OLITERAL/OPACK node in case context has changed.
- if n.Typecheck() == 1 {
+ if n.Typecheck() == 1 || n.Typecheck() == 3 {
switch n.Op() {
case ir.ONAME, ir.OTYPE, ir.OLITERAL, ir.OPACK:
break
@@ -1640,7 +1640,7 @@ func checkassignto(src *types.Type, dst ir.Node) {
return
}
- if op, why := assignop(src, dst.Type()); op == ir.OXXX {
+ if op, why := Assignop(src, dst.Type()); op == ir.OXXX {
base.Errorf("cannot assign %v to %L in multiple assignment%s", src, dst, why)
return
}