Skip to content

Analyzer allows writing to late final instance variables #43200

@stereotype441

Description

@stereotype441

The following program is accepted by the analyzer but rejected by the CFE:

class C {
  late final int x = 0;
  C(int value) {
    x = value;
  }
}
main() {
  print(C(1).x);
}

I believe this is the relevant spec text:

A non-local late variable declaration D implicitly induces a getter
into the enclosing scope. It also induces an implicit setter iff one of the
following conditions is satisfied:

  • D is non-final.
  • D is late, final, and has no initializing expression.

Since the declaration of x is late, final, and has an initializing expression, it meets neither of these conditions, so there should be no implicit setter and the assignment x = value should be illegal.

Metadata

Metadata

Assignees

Labels

NNBDIssues related to NNBD Releaselegacy-area-analyzerUse area-devexp instead.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions