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

Invalid const object field: Closure: (int) => int from Function 'defaultBar': static. #31066

Closed
jakobr-google opened this Issue Oct 11, 2017 · 3 comments

Comments

Projects
None yet
4 participants
@jakobr-google
Contributor

jakobr-google commented Oct 11, 2017

This code:

typedef int Bar(int value);

int defaultBar(int value) => value + 1;

class Foo {
  final Bar bar;

  const Foo._(Bar bar) : bar = bar ?? defaultBar;

  const Foo.baz({Bar bar}) : this._(bar); // <-- here
}

void main() {
  final foo = const Foo.baz();
  print(foo.bar(1));
}

fails with error: line 14 pos 30: Invalid const object field: Closure: (int) => int from Function 'defaultBar': static.

If I change line 10 to

  const Foo.baz({Bar bar = defaultBar}) : this._(bar);

then everybody's happy. If I instead change Bar to be a class (with a const constructor), and defaultBar to a const instance of Bar, then there are also no complaints.

I would've liked the the code above to work. Should it?

@a-siva

This comment has been minimized.

Show comment
Hide comment
@a-siva

a-siva Oct 17, 2017

Contributor

This looks like a duplicate of #31106
Marking as duplicate and closing, we will track this bug in the other issue.

Contributor

a-siva commented Oct 17, 2017

This looks like a duplicate of #31106
Marking as duplicate and closing, we will track this bug in the other issue.

@a-siva a-siva closed this Oct 17, 2017

@crelier

This comment has been minimized.

Show comment
Hide comment
@crelier

crelier Oct 23, 2017

Member

This is not a duplicate of #31106. I will have a look.

Member

crelier commented Oct 23, 2017

This is not a duplicate of #31106. I will have a look.

@crelier crelier reopened this Oct 23, 2017

@crelier crelier self-assigned this Oct 23, 2017

@crelier

This comment has been minimized.

Show comment
Hide comment
@crelier

crelier Oct 24, 2017

Member

This was almost a duplicate of 31106, but not quite. The right-hand side of operator ?? was not canonicalized when a constant. I find the handling of const (and potentially const) expressions in the parser quite fragile. This is probably not the last "duplicate" issue.
CL on its way.

Member

crelier commented Oct 24, 2017

This was almost a duplicate of 31106, but not quite. The right-hand side of operator ?? was not canonicalized when a constant. I find the handling of const (and potentially const) expressions in the parser quite fragile. This is probably not the last "duplicate" issue.
CL on its way.

@whesse whesse closed this in 61251c2 Oct 24, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment