You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
go/types: API allows instantiation of instantiated type #72978
Consider: https://go.dev/play/p/SiV_jaPuzNr
Re-Instantiation of the instantiated type of x in the code works unexpectedly.
Re-Instantiation of the instantiated type of f in the code fails as expected.
This seems inconsistent. Either we permit both or neither.
This is just a bug: there are no type params to substitute in the double-instantiated instance. The underlying is the same as the first instance. https://go.dev/play/p/6WDvAzt01tY
It seems we are just missing a check that there are no type arguments.
I suggest to fix this by reintroducing the check in instantiate.go. For example:
case *Named:
+ // Verify type parameter count for named types+ tparams := orig.TypeParams()+ if !check.validateTArgLen(pos, orig.obj.Name(), tparams.Len(), len(targs)) {+ return Typ[Invalid]+ }+ if tparams.Len() == 0 {+ // No type parameters to substitute (orig is not generic or already instantiated)+ return orig // nothing to do+ }
res = check.newNamedInstance(pos, orig, targs, expanding) // substituted lazily
This should restore the original behavior and prevent double instantiation. Happy to work on a CL if this approach looks acceptable.
Activity
findleyr commentedon Mar 21, 2025
This is just a bug: there are no type params to substitute in the double-instantiated instance. The underlying is the same as the first instance.
https://go.dev/play/p/6WDvAzt01tY
It seems we are just missing a check that there are no type arguments.
KirtanSoni commentedon Mar 23, 2025
May I propose a PR or a Plan on this?
obeyda commentedon Mar 27, 2025
Hi,
It looks like the double instantiation check was removed in CL 333589 when the instantiation logic was moved from
subst.gotoinstantiate.go.Current state:
go/src/cmd/compile/internal/types2/instantiate.go
Lines 128 to 131 in 1763ee1
I suggest to fix this by reintroducing the check in
instantiate.go. For example:This should restore the original behavior and prevent double instantiation. Happy to work on a CL if this approach looks acceptable.
gopherbot commentedon Apr 16, 2025
Change https://go.dev/cl/666115 mentions this issue:
go/types, types2: add missing generic type test to Checker.Instantiategopherbot commentedon Apr 17, 2025
Change https://go.dev/cl/666435 mentions this issue:
go/types, types2: add tests for duplicate instantiationgopherbot commentedon Jun 12, 2026
Change https://go.dev/cl/790040 mentions this issue:
go/types, types2: add missing generic test to Checker.Instantiatego/types, types2: add missing generic test to Checker.Instantiate