diff options
author | Robert Griesemer <gri@golang.org> | 2021-04-07 18:27:08 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2021-04-10 19:02:06 +0000 |
commit | a6d95b4508cb65070fd8471ae8018b897da7fc83 (patch) | |
tree | 02c9e3b75cd44a13ad85e2b5e78efba3f0dbce01 /src/cmd/compile/internal/types2/index.go | |
parent | 36c5f902f9049b82da50ac66049371830e6de031 (diff) | |
download | go-a6d95b4508cb65070fd8471ae8018b897da7fc83.tar.gz go-a6d95b4508cb65070fd8471ae8018b897da7fc83.zip |
cmd/compile/internal/types2: split out function instantiation from index expr
Also, factor out recording of type/value information after
evaluating an expression into an operand, so that we can
use it when handling instantiation expressions manually.
Change-Id: I6776e6cc243558079d6a203f2fe0a6ae0ecc33de
Reviewed-on: https://go-review.googlesource.com/c/go/+/308371
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/index.go')
-rw-r--r-- | src/cmd/compile/internal/types2/index.go | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/cmd/compile/internal/types2/index.go b/src/cmd/compile/internal/types2/index.go index 0f4adab237..b9b5b53226 100644 --- a/src/cmd/compile/internal/types2/index.go +++ b/src/cmd/compile/internal/types2/index.go @@ -11,14 +11,18 @@ import ( "go/constant" ) -func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) { +// If e is a valid function instantiation, indexExpr returns true. +// In that case x represents the uninstantiated function value and +// it is the caller's responsibility to instantiate the function. +func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) (isFuncInst bool) { check.exprOrType(x, e.X) - if x.mode == invalid { + + switch x.mode { + case invalid: check.use(e.Index) return - } - if x.mode == typexpr { + case typexpr: // type instantiation x.mode = invalid x.typ = check.varType(e) @@ -26,13 +30,11 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) { x.mode = typexpr } return - } - if x.mode == value { + case value: if sig := asSignature(x.typ); sig != nil && len(sig.tparams) > 0 { // function instantiation - check.funcInst(x, e) - return + return true } } @@ -194,6 +196,7 @@ func (check *Checker) indexExpr(x *operand, e *syntax.IndexExpr) { } check.index(index, length) + return } func (check *Checker) sliceExpr(x *operand, e *syntax.SliceExpr) { |