@griesemer@findleyr In this example, the types2 typechecker is allowing the G(1) argument of f() to be assigned to its one parameter, which has 'uint' type, without explicit conversion. Is that intentionally allowed, or just something that is happening with the implementation?
G(1) has type typeparam, or possibly (depending on final definitions) the type of the constraint 'interface { uint }'. I don't think there is any current assignability rule that makes it clear that we should be able to assign a type param or 'interface { uint }' to a uint, even though there is only one single underlying type 'uint' in the constraint. But maybe we are intending to add that? (I know obviously there hasn't been time to update the assignability rules fully in the spec.) I guess such a new rule may be implied by a bunch of the SingleUnder/Structure implementation work. Just want to be clear on what's allowed or not.
I've recently updated checking of assignments and I may have gone a bit too far. So this may (or may not be intended). Will discuss with @ianlancetaylor .
The implementation of the assignability check was too loose. Two named types (defined types, predeclared types, or type parameters) with different names, are not assignable without explicit conversion. This is a bug in the type checker.
That said, this seemingly equivalent program compiles fine:
package p
func_[Pint](xP) int {
returnx
}
func_[Pint]() int {
returnP(1)
}
griesemer
added
NeedsFix
The path to resolution is known, but the work has not been done.
and removed
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
labels
Oct 31, 2021
Tentatively labeling this as a release blocker since it's a compiler crasher on a valid program with typeparameters.
cc @randall77 @danscales
The text was updated successfully, but these errors were encountered: