Skip to content

Allow Function getters to be overriden as actual functionsΒ #4159

Open
@FMorschel

Description

@FMorschel

If you have code like the following:

typedef MyAPI = int Function(int a, int b);

class A {
  int m(int a, int b) => a + b;
}

class B {
  void m(MyAPI api) {
    print(api(1, 2));
  }
}

void main() {
  var b = B();
  var a = A();
  b.m(a.m);
}

Say you are creating a package and have not added testing or actually called the last line above (b.m(a.m)) anywhere. There is no way for you to know that the call will break.

If you have something like this:

typedef MyAPI = int Function(int a, int b);

abstract class Base {
  MyAPI get m;
}

class BaseA extends Base {
  @override
  MyAPI get m => (a, b) => a + b;
}

class B {
  void m(MyAPI api) {
    print(api(1, 2));
  }
}

void main() {
  var b = B();
  var a = BaseA();
  b.m(a.m);
}

The code will also work but the declaration at BaseA for m is not the best for writing down.

I'd like to ask for function getters to be able to be written as actual functions since they would work the same way.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureProposed language feature that solves one or more problems

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions