]> Cypherpunks repositories - gostls13.git/commit
cmd/compile: make sure imported instantiated types have their methods created
authorDan Scales <danscales@google.com>
Mon, 6 Sep 2021 23:25:43 +0000 (16:25 -0700)
committerDan Scales <danscales@google.com>
Tue, 7 Sep 2021 20:37:05 +0000 (20:37 +0000)
commit80783558b06741beaf41dbd198013fe3a13c9ad2
tree5a2b8582afba8399f5df09c5b93818244870808f
parent23f4f0db682fad0c8d61a5b5cdbdbad4cf1cd41f
cmd/compile: make sure imported instantiated types have their methods created

We should be putting a newly instantiated imported type in
Instantiate/doInst onto the instTypeList, so its methods/dictionaries
are instantiated. To do this, we needed a more general way to add a
type to instTypeList, so add NeedInstType(), analogous to
NeedRuntimeType(). This has the extra advantage that now all types
created by the type substituter are added to instTypeList without any
extra code, which was easy to forget. doInst() now correctly calls
NeedInstType().

This is a bit aggressive, since a fully instantiated type in a generic
function/method may never be used, if the generic method is never
instantiated in the local package. But it should be fairly uncommon for
a generic method to mention a fully instantiated type (but it does
happen in this bug).

Fixes both cases mentioned in the bug.

Fixed #48185

Change-Id: I19b5012dfac17e306c8005f8595a648b0ab280d0
Reviewed-on: https://go-review.googlesource.com/c/go/+/347909
Trust: Dan Scales <danscales@google.com>
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/compile/internal/noder/expr.go
src/cmd/compile/internal/noder/irgen.go
src/cmd/compile/internal/noder/stencil.go
src/cmd/compile/internal/noder/types.go
src/cmd/compile/internal/typecheck/iimport.go
src/cmd/compile/internal/typecheck/subr.go
test/typeparam/issue48185b.dir/a.go [new file with mode: 0644]
test/typeparam/issue48185b.dir/main.go [new file with mode: 0644]
test/typeparam/issue48185b.go [new file with mode: 0644]