-
Notifications
You must be signed in to change notification settings - Fork 26
Type check failures throw StrongModeError more eagerly than needed #296
Comments
discussed solution here, essentially:
The nice thing about that fix: if you avoid creating objects with a reified |
On a very related note, after #236, strong mode and standard Dart print different values for: class Foo<T> {
bool bar(x) => x is T;
}
void main() {
Foo<int> foo = new Foo();
print(foo.bar("hello"));
} We used to reject this. @leafpetersen - maybe we should split this issue out? |
Though I added that example here as @jmesserly 's solution (3) should require a |
ah, because of inference... eeeep. class Foo<T> {
bool bar(x) => x is T;
}
void main() {
Foo<int> foo = new Foo();
var foo2 = new Foo<int>();
print(foo.bar("hello"));
print(foo2.bar("hello"));
} it seems really nice if |
I guess we could track "inferred type T" at runtime, not sure if that's way too crazy... |
Yes, the coherence of generic parameter inference relative to the regular Dart semantics was based on the following reasoning:
With this change, we no longer statically reject non-ground is checks, so we lose property 2. Property 3 also gets a bit hinky in that we may throw a CastError instead of a StrongModeError, but that strikes me as less problematic. Tracking at runtime which generic parameters and function type components were originally dynamic and got improved via inference doesn't seem too hard to me, and should resolve this. If the "inferred" bit for a type
So we would have that: List<String> inferred = []
List<String> annotated = <String>[]
(inferred is List<String); // true
(inferred is List<int>); // StrongModeError
(inferred is List; // true
(inferred is Future<int>); // false
(annotated is List<String); // true
(annotated is List<int>); // false
(annotated is List); // true
(annotated is Future<int>); // false |
I think @leafpetersen may have fixed this :) |
I fixed the original reported issue: we now only throw when we can't be sure that spec mode would have given the same answer, given the types in question. However, the inference issue is still live: inference can change what types we're asking the question about, and we're not tracking that yet. We can either leave this bug live for that, or open a new one, either way. |
Yeah I'll split that. Thanks! |
#567 for the other bug |
Now that we're statically allowing more is and as checks (#236), we instead throw a StrongModeError at runtime in problematic cases.
We throw these in cases we don't really need to. E.g.,
<int>[] is List<String>
can safely return false even though:
x is List<String>
may be problematic in general.
The text was updated successfully, but these errors were encountered: