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
cmd/compile: instantiation cycle in closure function created by method of generic type #50215
I think the error is correct. StringParser[T]'s ToListParser method has a return type of StringParser[[]T]. This means if we want to instantiate StringParser[int], then we'll also have to instantiate StringParser[[]int] too; which then means we'll also have to instantiate StringParser[[][]int], etc etc.
which then means we'll also have to instantiate StringParser[[][]int],
Could you explain how this follows from the previous part? There are no method calls for StringParser[[]int], so it looks like there should never be any need to consider StringParser[[][]int].
Could you explain how this follows from the previous part?
Go allows method calls to happen dynamically through interface assertions or reflection. As a result, if a type is instantiated, all of its methods must be instantiated too, even if not statically called.
There are certainly cases where we could determine this isn't actually needed, but that would complicate the language specification.
Activity
randall77 commentedon Dec 16, 2021
@mdempsky
mdempsky commentedon Dec 16, 2021
I think the error is correct.
StringParser[T]'sToListParsermethod has a return type ofStringParser[[]T]. This means if we want to instantiateStringParser[int], then we'll also have to instantiateStringParser[[]int]too; which then means we'll also have to instantiateStringParser[[][]int], etc etc.zhuah commentedon Dec 17, 2021
@mdempsky thank you, i got it.
it' may better be reported as infinite instantiation instead of cycle ?
typesanitizer commentedon Jan 11, 2022
Could you explain how this follows from the previous part? There are no method calls for
StringParser[[]int], so it looks like there should never be any need to considerStringParser[[][]int].Similar code in (say) Rust compiles just fine:
mdempsky commentedon Jan 11, 2022
Go allows method calls to happen dynamically through interface assertions or reflection. As a result, if a type is instantiated, all of its methods must be instantiated too, even if not statically called.
There are certainly cases where we could determine this isn't actually needed, but that would complicate the language specification.