Skip to content

Late final field inference #4708

Description

@sgrekhov

According to the inference specification

The type of a final field which overrides/implements both a setter and a getter is inferred to be the return type of the combined member signature of said getter in the direct superinterfaces.
...
Note that late fields are inferred exactly as non-late fields. However, unlike normal fields, the initializer for a late field may reference this.

How the type of a late final field should be inferred? According to the above it should be inferred as a final non-late field. But in fact

class A {
  void set m1(String _) {}
  num get m1 => 3.14;
  void set m2(String _) {}
  int get m2 => 42;
}

class C extends A {
  late final m1 = 0; // Ok, inferred as num
  late final m2; // Error. The setter 'C1.m2' ('void Function(int)') isn't a valid override of 'A.m2' ('void Function(String)')
}

This behavior is OK, but perhaps it makes sense to adjust the specification and clarify that the type of a late final field with no initializer is inferred as a type of a non-final field?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThere is a mistake in the language specification or in an active documentspecification

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions