Skip to content

Extensions for getters don't work on classes that define a setter with the same name. #60471

@jellynoone

Description

@jellynoone

Consider:

// submit
void main(List<String> args) {
  A().a; // not found
}

class A {
  set a(int value) {}
}

extension on A {
  int get a => 0;
}

The .a access is not found even though there is an extension on A that defines it. I'm not sure if this is intended or not considering A defines a setter?

Concrete example, where fixing this bug would be useful:

// Assuming flutter:
abstract interface class ValueListenable<T> {
  T get value;
  void addListener(void Function() listener);
  void removeListener(void Function() listener);
}

// package:library
abstract interface class MyController {
  ValueListenable<MyState> get state;

  set a(int a);
}

class MyState {
  final int a;

  const MyState({
    required this.a,
  });
}

// my_app
void main() {
  final controller = MyController();

  print(controller.a); // Accessing the value of 'a' from `MyState` via getter 
}

extension on MyController {
  int get a => state.value.a;
}

dart --version
Dart SDK version: 3.7.2 (stable) (Tue Mar 11 04:27:50 2025 -0700) on "macos_arm64"

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions