Generate checks at generic function instantiation with dynamically checked bound. #33726
Labels
area-language
Dart language related items (some items might be better tracked at github.com/dart-lang/language).
area-specification (deprecated)
Deprecated: use area-language and a language- label.
Cf. the discussion in #31953: When a generic function is evaluated (as a tear-off, not as an invocation) in a context where (after inference, if any) the expected type is a non-generic function, generic function instantiation will take place. Please see the proposed feature specification for details.
That feature specification considers the situation where the inferred type argument list is not guaranteed to satisfy the declared bounds to be a compile-time error. However, as demonstrated by the discussion in #31953, it may be useful to accept such unsafe inferred type arguments in some cases, which brings up the question about when to fail in the case where the actual type argument list is indeed a bound violation.
We may produce the error at the location where the generic function instantiation takes place (considering that location to denote a tear-off operation which passes the type arguments), and we may produce the error at each invocation of the torn-off function (corresponding to an understanding of the generic instantiation as the implicit generation of a wrapper function).
The discussion in #31953 seems to have reached the conclusion that the former is preferable:@rakudrama said so here, @leafpetersen said 'lets go with an early (instantiation time) error for now' here, @lrhn said 'I prefer to check early' here. In the opposite direction, @sjindel-google argued here that it would require extra work in the VM to throw early.
This issue is concerned with making a decision in the language team to throw early or late.
The text was updated successfully, but these errors were encountered: