-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Error creating super mixin on class with no default 0 arg ctor #35011
Comments
Classifying as "area-language" for now since we're not sure whether analyzer or front end behavior is correct. @leafpetersen, @eernstg, @lrhn, can you let us know which behavior is correct, so we can reassign the bug to analyzer or front end as appropriate? |
The analyzer is correct, and so is the code. Mixin declarations are not class declarations, and their super-class constraints are not super-classes. Mixin declarations have no constructors, and they do not need to call a super-constructor, so should make no difference which constructors their super-constraint classes have. I get the same error from both dart2js and the VM, so it's most likely a front-end issue. If I change the code to: class X {}
class NoDefaultZeroArgCtor implements X {
NoDefaultZeroArgCtor(int x);
...
}
mixin FooMixin on NoDefaultZeroArgCtor, X {
... then the program runs. It seems that the front-end is introducing an abstract interface in the case where there are more than one super-constraint, and that interface does have an unnamed nullary constructor, so their hack works. It should work in the one-constraint case too. |
The corresponding code with old-style super mixins would have had: class FooMixin extends NoDefaultZeroArgCtor {
int foo() => super.foo();
} which would have signaled the same error; and there was no way to repair it by adding a constructor to So this is a problem affecting new code using mixin declarations, but not for porting existing code using old-style super mixins because it wouldn't have worked in the first place. I'm testing a fix. |
I'm running into this bug with the 2.1.0 candidate. |
See https://travis-ci.org/dart-lang/site-www/builds/455227237. I've got a smaller repro, if you want it. |
Here's the smaller repro (passes analysis but fails to run unless you swap in the commented-out lines):
|
I suppose @MichaelRFairhurst's repro is better/shorter. :) |
* 2.1-ify the source code * Add int-to-double words; add/update int & double code * Say that dart:async import isn't always required * Update mixin description for 2.1 * Workaround for 2.1.0 mixin bug: dart-lang/sdk#35011
This is fixed but the fix somehow missed the final 2.1 dev release. The fix landed before the last push to dev, so I assumed that it had made it in and didn't request a merge to dev. I'm sorry about that. So this is now an (extremely) annoying bug in the new 2.1 feature that will be fixed in the next release. |
@kmillikin if this is supposed to go into the 2.1.1 stable release, please file a merge-to-stable request. |
Not sure if this is helpful, but here is an example that fails on 2.1.0 class Cook = Person with AwesomeCookingSkills;
class Person {
final String name;
Person(this.name);
}
mixin AwesomeCookingSkills on Person {
String get bestDish => "$name makes the best chocolate.";
}
main() {
final cook = Cook("Johnny Appleseed");
/// Error: The superclass, 'Person', has no unnamed constructor that takes no arguments.
print(cook.bestDish);
} And here is a Gist if it's useful for tracking this https://dartpad.dartlang.org/b4f766621b01ffa5270e5de93ef592b5 |
Did this miss 2.1.1 or is it just not in the changelog? https://github.com/dart-lang/sdk/blob/master/CHANGELOG.md#211---2019-02-18 |
It should be in 2.1.1. |
Repro:
via
dart
:via
dartanalyzer
:The latter seems desirable to me, though I can only hazard a guess at if there's a good reason why the former is the required/correct behavior.
The text was updated successfully, but these errors were encountered: