-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.genericsIssue is related to genericsIssue is related to genericsokay-after-beta1Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1release-blocker
Milestone
Description
This code corresponds to Fig. 10 in the paper "Featherweight Go" ("FGG"); it's an example of a program that cannot be monomorphised.
The type checker (types2
, go/types
) accept this fine, but the compiler runs "forever".
package main
type Box[A any] struct {
value A
}
func Nest[A any](b Box[A], n int) interface{} {
if n == 0 {
return b
}
return Nest(Box[Box[A]]{b}, n-1)
}
func main() {
Nest(Box[int]{0}, 10)
}
The FGG paper suggests a check to detect such cases. We may want to implement that eventually. For 1.18, maybe we can have some sort of "time-out" with a suitable error message for now.
cc: @randall77
sithumonline and MagnificRogue
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.genericsIssue is related to genericsIssue is related to genericsokay-after-beta1Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1release-blocker