Skip to content

Post NNBD setter/getter consistency requirements #331

Closed
@leafpetersen

Description

@leafpetersen

With --no-implicit-casts turned on, the analyzer currently makes the following an error:

class A {
  void set f(int x) {}
  Object get f => 3;
}

I believe this is an unintentional result of making assignable asymmetric. The specification says that:

It is a static warning if a class has
a setter named \code{$v$=} with argument type $T$ and
a getter named $v$ with return type $S$,
and $S$ may not be assigned to $T$.

Turning on --no-implicit-casts essentially re-interprets "$S$ may not be assigned to $T$" to be "$S$ is not a subtype of $T$".

Do we want to treat this as a bug and fix it, or is this the right behavior for the post NNBD world.

In it's defense, this "bug" is enforcing the very sane property that a.f = a.f should not be a type error.

cc @nshahan @munificent @lrhn @eernstg

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions