-
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
bug using redirecting constructor in initializer of extension type #55135
Comments
That sounds like a bug. You should be able to subtype typed data with extension types. |
Are you running this with DDC? For my part, this code: import 'dart:math';
import 'dart:typed_data';
extension type const Point._(Float64x2 point) implements Float64x2 {
Point(double x, double y) : point = Float64x2(x, y);
double get distance => sqrt(point.x * point.x + point.y * point.y);
}
void main() {
print('Float64x2: ${Float64x2(0, 0)}');
print(Point(0, 0));
print('Point: ${Point(0, 0)}');
} prints this with the Dart VM (3.3.0):
and prints this in DartPad (DDC):
with the following exception in the console:
suggesting some weird things: |
Yes, I should have mentioned that was in DartPad. Initially was trying to add it to a |
Should this get moved to the |
It appears this is triggering issues on both web compilers, coincidentally. Likely these are different bugs. Both trigger when the initializer of the extension type representation field uses a redirecting factory constructor (which class B implements A {
final int x = 1;
}
abstract class A {
int get x;
factory A() = B;
}
extension type C._(A point) implements A {
C() : point = A(); // << initializer is redirecting factory
}
void main() {
print(A().x);
print(C().x);
} This program compiles in DDC, but like above gets Dart2js surprisingly crashes! Here is the crash error for the same program:
|
This looks like an issue with the lowering of redirecting factory constructors for both js compilers. @sigmundch example above looks like a good reproduction of the problem. |
#55079 is likely the same bug in dart2js. |
Moving temporarily to area-frontend, we can move it back if in fact it's an issue on the web compilers. |
I might have a solution. I'm working on it in https://dart-review.googlesource.com/c/sdk/+/357161. |
Thanks so much for the fix @chloestefantsova! @chloestefantsova @johnniwinther - since the fix is fairly contained, it seems it may be worth considering filing a cherry-pick request for it. What do you think? |
That's a good idea. I've just filed #55194. |
…Child The added method is required for the resolution of redirection targets to work: it replaces the immediate target invocation node with the final target invocation node. Closes #55135 Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/357161 Cherry-pick-request: #55194 Change-Id: I96643c5af0ca91209cd936aee78f13c416679275 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/357600 Commit-Queue: Chloe Stefantsova <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
Extension types don't seem to support typed data, for instance
Float64x2
.There is a restriction that typed_data isn't extended, but that applies to other types like
int
,double
, which extension types can use.I was checking to see if extension types would be more performant in the case of
Offset
, but usingList<double>
is actually slower from my tests.The text was updated successfully, but these errors were encountered: