-
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
Analyzer and CFE disagree on promotion of this
.
#40932
Comments
I do want promotion of So, yes please, let's fix this now. |
R=brianwilkerson@google.com, paulberry@google.com Bug: #40932 Change-Id: Ie0fd3554fcb1f8baa3944bd6805ac72f0b76da61 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138841 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Oh, I missed the part about classes. Do we do promotion of |
For code in the body of a method which is inherited, a promotion could be both safe and useful. So, yes, I think classes should support promotion of |
@johnniwinther seems to think that this is actually not supported by the front end, and that presumably the reason I'm not seeing errors for the example above is because errors are suppressed in NNBD mode, and implicit casts are allowed in non-NNBD mode. The modified example below which makes the implicit downcast a sidecast seems to validate this. Given that this is not implemented in the CFE either, we should re-evaluate whether to spend time on this now. extension Test on A {
C get foo {
A self = this;
if (this is C) return this;
if (self is C) return self;
return C();
}
}
class A {
C get foo {
A self = this;
if (this is C) return this;
if (self is C) return self;
return C();
}
}
class B extends A implements C {}
class C {}
void main() {} |
Would there be any risk of lock-in if we don't do Since our promotion is only to subtypes, invocations should stay sound, but extension methods might get shadowed if we start promotiong. The biggest risk is that someone does class Foo {
if (this is Bar) {
var list = [this];
}
} and starts getting a So, it's not completely non-breaking to promote |
Just note that the "just treat |
This is consistent in the two front ends, and I don't think this is something we should try to push into the null safety release. I filed a language issue to track the desire to do better here, closing this out. |
With the non-nullable experiment on, I see errors from the analyzer on the
return this
statements in the extension and class below. The CFE gives no errors.I believe this may be a long-standing issue, should we try to resolve this in the NNBD release?
cc @scheglov @johnniwinther @lrhn @munificent @eernstg @stereotype441
The text was updated successfully, but these errors were encountered: