Skip to content
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 an error when the class has a const constructor, and a mixin declares a field. #33645

Closed
scheglov opened this issue Jun 27, 2018 · 3 comments
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. front-end-missing-error

Comments

@scheglov
Copy link
Contributor

See #33644

@scheglov scheglov changed the title It is OK to declare a const constructor in a class with a mixin It is an error when the class has a const constructor, and a mixin declares a field. Jun 27, 2018
@JekCharlsonYu JekCharlsonYu added this to the AnalyzerCFE milestone Jun 27, 2018
@chloestefantsova chloestefantsova self-assigned this Jul 23, 2018
@chloestefantsova
Copy link
Contributor

I believe this issue and #33644 have the same cause: fasta doesn't allow mixin applications to have const constructors.

@chloestefantsova chloestefantsova moved this from To do to In progress in Analyzer/FE Integration Jul 23, 2018
@chloestefantsova
Copy link
Contributor

/cc @askeksa-google

@eernstg
Copy link
Member

eernstg commented Aug 6, 2018

I believe that the title may give rise to some confusion. Maybe it could be 'It is an error for a class to have a constant constructor if its superclass is a mixin application S with M where M has a field'?

The "interesting" case where an error arises even though everything seems to be OK is the following:

class S { const S.foo(); }
class M { final x = 42; }
class A extends S with M { const A.foo(): super.foo(); }

In this situation we could have written the mixin application as a regular class (with an explicit declaration of the forwarding constant constructor), and everything would just work:

class S { const S.foo(); }
class SwithM extends S { final x = 42;  const SwithM.foo(): super.foo(); }
class A extends SwithM { const A.foo(): super.foo(); }

So even in this case where "it should just work", we get an error because the mechanism that generates forwarding constructors just won't generate a constant one when there is a field.

The justification for making this an error is that a final field with a constant initializing expression is a pretty useless thing. ;-)

@bwilkerson bwilkerson removed this from In progress in Analyzer/FE Integration Aug 28, 2018
@bwilkerson bwilkerson removed this from the AnalyzerCFE milestone Aug 28, 2018
@bwilkerson bwilkerson added area-front-end Use area-front-end for front end / CFE / kernel format related issues. and removed area-analyzer-cfe labels Aug 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues. front-end-missing-error
Projects
None yet
Development

No branches or pull requests

6 participants