Cascade specification doesn't allow static type checking. #19517
Labels
area-language
Dart language related items (some items might be better tracked at github.com/dart-lang/language).
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
The specification of cascade invocation just says that e..suffix is equivalent to (t){t.suffix; return t;}(e) .
The "t" variable isn't typed, so there should be no warning for, e.g.,
"abc"..noMethodNamedThis()
Also, the return type of the function literal is dynamic, so the type of e is lost there too:
("abc"..toString()).noMethodNamedThis()
should also not give a warning.
Could the spec of cascade be rewritten to not erase the type, e.g.,:
... equivalent to (((T t) { t.suffix; return t;})(e) as T) where T is the static type of e.
Or, alternatively, give static typing rules for cascades explicitly:
e..suffix
has the static type T where T is the static type of e, and gives a warning if e.suffix would give a warning.
The text was updated successfully, but these errors were encountered: