Skip to content

Error for using a lambda in a setter #25642

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
alan-knight opened this issue Feb 2, 2016 · 5 comments
Closed

Error for using a lambda in a setter #25642

alan-knight opened this issue Feb 2, 2016 · 5 comments
Labels
legacy-area-analyzer Use area-devexp instead. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@alan-knight
Copy link
Contributor

The analyzer recently changed so that

set foo(x) => _foo = x;

is a type error. It can't cause anything to go wrong, but it's a bit confusing. But it's also a severe error that prevents compilation, so the couple of occurrences of this in the Intl package prevent Angular from compiling. This seems overkill for something that can never be a runtime problem.

@bwilkerson bwilkerson added Type-Defect P1 A high priority bug; for example, a single project is unusable or has many test failures legacy-area-analyzer Use area-devexp instead. labels Feb 2, 2016
@zoechi
Copy link
Contributor

zoechi commented Feb 2, 2016

See also #25228

@jmesserly jmesserly removed their assignment Feb 2, 2016
@jmesserly
Copy link

@vsmenon -- thoughts on this one?

it was caused by #25228. We'll also infer "void" as the setter return type in strong mode (Which was itself a user request. It catches incorrect "return", which means you can leave off the "void" with no change in the type system. Leaving off "void" is required by style guide.)

I'm persuaded by arguments from folks on #25228 (comment) though. The => form is very convenient. I think we could allow it in strong mode.

@vsmenon vsmenon assigned vsmenon and leafpetersen and unassigned vsmenon Feb 2, 2016
@vsmenon
Copy link
Member

vsmenon commented Feb 2, 2016

We're arguably somewhat inconsistent right now:

typedef void FOO(int x);
int y;
FOO foo = (int x) => y = x; // OK
void bar(int x) => y = x; // Warning
FOO foo2 = bar; // OK!

It's a bit odd we complain about bar, but not assignments.

@leafpetersen ?

@munificent munificent mentioned this issue Feb 18, 2016
35 tasks
@jmesserly jmesserly added Priority-Medium and removed P1 A high priority bug; for example, a single project is unusable or has many test failures labels Feb 18, 2016
@munificent munificent changed the title Severe fatal error for using a lambda in a setter Error for using a lambda in a setter Feb 18, 2016
@leafpetersen leafpetersen removed their assignment Feb 24, 2016
@trinarytree
Copy link

I'm curious about why => is considered "very convenient" for setters. It's actually more verbose than using {}s by 1 character:

class A {
  var _x;
  set x(value) => _x = value;
  set x(value) {_x = value;}
}

One might try to argue that the dart formatter will transform the version with {}s into 3 lines, but ok, if that's such a problem, change the dart formatter, not the language.

There is a real downside to having => in setters. It makes it look like the return value is significant, e.g. that it may affect the value of assignment expressions like a = b = c.

@jmesserly jmesserly added P3 A lower priority bug or feature request and removed Priority-Medium labels Feb 29, 2016
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed Type-Defect labels Mar 1, 2016
@srawlins
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

9 participants