-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DDC strong mode and exact types #30546
Comments
Adding a bit of context: We need to specify if/when the strong mode static analysis determines that a given expression has an exact type, and what that knowledge is used for. A typical case would be constant expressions, where the exact type is known at compile-time, but In the given context, a downcast from "exactly When we have a clear model for which expressions have exact types, and when that's used for what, we can adjust the tests to have the correct expectations. |
The intention is that the error only be issued on casts that are guaranteed to fail. A reasonable approximation of this is to only issue this error when the target type of the implicit cast is a ground type. That would allow this cast. |
Related: class A {
const A();
}
class B extends A {
const B();
}
// Snip...
// Will be instantiated with U=dynamic and V=dynamic.
class Test5<U extends A, V extends B> {
final U x = const A(); //# 21: ok
final U x = const B(); //# 22: compile-time error
final V x = const A(); //# 23: ok
final V x = const C(); //# 24: compile-time error
final V x = const C.d(); //# 25: compile-time error
const Test5();
}
use(x) => x;
main() {
use(const Test1());
use(const Test2<A, B>());
use(const Test3<A, B>());
use(const Test4<A, B>());
use(const Test5());
}
|
// Will be instantiated with U=dynamic and V=dynamic.
class Test5<U extends A, V extends B> { This comment is incorrect for Dart 2, The The assignment Since the assignment of an |
Trying to actually run it, I can see that the use of exact types in DDC does play a role in Kevin's example after all, because DDC emits a compile-time error for subtest 21 (which is marked
We may check the initialization of So this means that Kevin's example shows an issue with DDK in relation to const expressions (23), and it again shows the issue with DDC and exact types that gave rise to this issue in the first place. |
I agree that And |
this still reproduces. should be a quick fix |
https://dart-review.googlesource.com/c/sdk/+/62663 ... does not fix CFE tho, which appears to be expecting these as failures (perhaps ported the bug from Analyzer?) |
Closing since both CFE and analyzer seem to agree on disallowing these casts: https://dart-review.googlesource.com/c/sdk/+/115778 Feel free to re-open if this is premature. |
In strong-mode the following test fails (from compile_time_constant_static5_test):
class A {
const A();
}
class Test3<U extends A, V extends B> {
final U x = const A(); //# 11: ok
}
because the result is a compile-time warning.
This is changed behavior from earlier. Is the current behavior expected, then the test should be updated.
The text was updated successfully, but these errors were encountered: