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
It is OK to declare a const constructor in a class with a mixin #33644
Comments
I believe this issue and #33645 have the same cause: fasta doesn't allow mixin applications to have const constructors. |
/cc @askeksa-google |
I did some research (that is, talked to @eernstg :)), and it seems that it's not ok to declare a const constructor in a mixin application, but a const constructor is implicitly delcared in case there's one in the superclass of the mixin application, and the mixin doesn't have fields. So I think the example program in the original post of this issue should result in a compile-time error. The following example program is supposed to demonstrate the effect of implicitly declared const and not-const constructors in a mixin application. class M {}
class S {
const S.foo();
}
class A extends S with M {
// The following is implicitly declared:
//
// const A.foo() : super.foo();
}
class N {
int bar;
}
class B extends S with N {
// The following is implicitly declared:
//
// B.foo() : super.foo();
}
main() {
A a = const A.foo(); // Ok.
B b = const B.foo(); // Compile-time error.
} |
Ok, I had another conversation, and it seems that what I've written above is misleading. The implicitly declared constructors are declared within the mixin application class ( So, the example program in the original post should compile without errors, as rightfully suggested. And the compiler should produce a compile-time error for my example program, because there are no constructors Sorry for the inconvenience! |
Agreed! (so this example has no error; and the constructors are not implicitly created in |
This code should not give any errors, according to the current state of the language specification.
See
12.1 Mixin Application
:M
has no fields, soObject with M
has a constant default constructor.The text was updated successfully, but these errors were encountered: