Skip to content

Cannot have a const constructor even if members are const-constructible? #819

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

Closed
jamesderlin opened this issue Feb 6, 2020 · 2 comments
Closed
Labels
enhanced-const Requests or proposals about enhanced constant expressions request Requests to resolve a particular developer problem state-duplicate This issue or pull request already exists

Comments

@jamesderlin
Copy link

We'd like to have code like:

class Foo {
  const Foo(this.value);

  final int value;
}

class FooDelegate implements Foo {
  final Foo _foo;

  const FooDelegate(int value) : _foo = Foo(value); // Line 10

  @override
  int get value => _foo.value;
}

but this fails with:

error • Invalid constant value. • const_delegate.dart:10:41 • invalid_constant

We could remove const from the FooDelegate constructor, but without it FooDelegate is no longer perfectly substitutable for Foo (const foo = FooDelegate(1); would fail).

It would be nice if there were some way for a const constructor to const-construct members if possible.

@jamesderlin jamesderlin added the request Requests to resolve a particular developer problem label Feb 6, 2020
@eernstg
Copy link
Member

eernstg commented Feb 6, 2020

@eernstg eernstg added the state-duplicate This issue or pull request already exists label Feb 7, 2020
@eernstg
Copy link
Member

eernstg commented Feb 7, 2020

dart-lang/sdk#20962 was moved to this repo, where it should be; marking this as duplicate of its new location, #823, and closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhanced-const Requests or proposals about enhanced constant expressions request Requests to resolve a particular developer problem state-duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants