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

Allow const constructor with mixins that have getter-only fields #37810

Closed
cpboyd opened this issue Aug 10, 2019 · 5 comments
Closed

Allow const constructor with mixins that have getter-only fields #37810

cpboyd opened this issue Aug 10, 2019 · 5 comments
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@cpboyd
Copy link

cpboyd commented Aug 10, 2019

Originally posted at google/built_value.dart#694

I'm getting const_constructor_with_mixin_with_field when using this mixin:

mixin RouteEnum on EnumClass {
  String get title;

  String get subtitle;

  IconData get icon;

  Color get color;
}

I have other code in the mixin that depends on those fields, which are defined in the subclass.

Since I'm not actually defining any fields in the mixin itself, it seems like this error shouldn't necessarily happen.

Shouldn't getter-only fields be treated similarly to functions?

Edit: Forgot to add my use case for this...
I'm using Flutter with a BottomNavigationBar and separate navigation within each tab.

As a result, I'd like to keep all of this related information with the EnumClass because it makes more sense structurally to me than to have functions within the various Widgets.

@lrhn
Copy link
Member

lrhn commented Aug 12, 2019

It shouldn't happen.
The mixin class does not declare any instance variable. I doesn't actually declare any concrete anything, it just adds members to its interface.

This is an implementation bug. I'll move it to the SDK repository.

Simple reproduction:

class C {
  const C();
}
mixin M {
  int get foo;DART_CONFIGURATION=ReleaseX64 .../sdk/bin/dartanalyzer_developer --dart-sdk=/usr/local/google/home/lrn/dart/co/sdk/sdk cmf.dart

}
class S extends C with M {
  const S();
  int get foo => 42;
}

main() {
 const S().foo;
}

gives the following error from the analyzer:

Analyzing cmf.dart...
  error • Const constructor can't be declared for a class with a mixin that declares an instance field at cmf.dart:8:9 • const_constructor_with_mixin_with_field
1 error found.

It should not. The common front-end does not give any error.DART_CONFIGURATION=ReleaseX64 .../sdk/bin/dartanalyzer_developer --dart-sdk=/usr/local/google/home/lrn/dart/co/sdk/sdk cmf.dart

@nyarian
Copy link

nyarian commented Jul 8, 2020

Any news?

@triallax
Copy link

triallax commented Jul 9, 2020

@nyarian this issue was fixed in 56dbe29.

@Peng-Qian
Copy link

Hi all,
when it available in Flutter?

@zs-dima
Copy link

zs-dima commented Jan 26, 2022

Any news about?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

7 participants