Skip to content

Commit

Permalink
cmd/compile/internal/types2: update the recorded function type after …
Browse files Browse the repository at this point in the history
…inference

This is a clean port of CL 353831 from go/types to types2.

For #47916.

Change-Id: I2c2b9c7bbcd416fb21f3032c55a06406bad9334a
Reviewed-on: https://go-review.googlesource.com/c/go/+/353934
Trust: Robert Griesemer <[email protected]>
Run-TryBot: Robert Griesemer <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Robert Findley <[email protected]>
  • Loading branch information
griesemer committed Oct 5, 2021
1 parent cbd7200 commit 5140ad1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/cmd/compile/internal/types2/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,10 @@ func TestTypesInfo(t *testing.T) {
// parameterized functions
{genericPkg + `p0; func f[T any](T) {}; var _ = f[int]`, `f`, `func[generic_p0.T₁ interface{}](generic_p0.T₁)`},
{genericPkg + `p1; func f[T any](T) {}; var _ = f[int]`, `f[int]`, `func(int)`},
{genericPkg + `p2; func f[T any](T) {}; func _() { f(42) }`, `f`, `func[generic_p2.T₁ interface{}](generic_p2.T₁)`},
{genericPkg + `p3; func f[T any](T) {}; func _() { f(42) }`, `f(42)`, `()`},
{genericPkg + `p2; func f[T any](T) {}; func _() { f(42) }`, `f`, `func(int)`},
{genericPkg + `p3; func f[T any](T) {}; func _() { f[int](42) }`, `f[int]`, `func(int)`},
{genericPkg + `p4; func f[T any](T) {}; func _() { f[int](42) }`, `f`, `func[generic_p4.T₁ interface{}](generic_p4.T₁)`},
{genericPkg + `p5; func f[T any](T) {}; func _() { f(42) }`, `f(42)`, `()`},

// type parameters
{genericPkg + `t0; type t[] int; var _ t`, `t`, `generic_t0.t`}, // t[] is a syntax error that is ignored in this test in favor of t
Expand Down
6 changes: 6 additions & 0 deletions src/cmd/compile/internal/types2/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,14 @@ func (check *Checker) callExpr(x *operand, call *syntax.CallExpr) exprKind {

// evaluate arguments
args, _ := check.exprList(call.ArgList, false)
isGeneric := sig.TypeParams().Len() > 0
sig = check.arguments(call, sig, targs, args)

if isGeneric && sig.TypeParams().Len() == 0 {
// update the recorded type of call.Fun to its instantiated type
check.recordTypeAndValue(call.Fun, value, sig, nil)
}

// determine result
switch sig.results.Len() {
case 0:
Expand Down

0 comments on commit 5140ad1

Please sign in to comment.