Skip to content

Wrapped function causes runtime error. #39818

Closed
@modulovalue

Description

@modulovalue

dartpad

I'm not sure how to describe this issue.

abstract class Interface {}

class Model implements Interface {}

class Lens<A> {
  final A Function(A) get;
  const Lens(this.get);
}

void main() {
  Lens<Interface> a = Lens<Model>((a) => a);  
  print(a.get); /// Script error / type '(Model) => Model' is not a subtype of type '(Interface) => Interface'
}

I'm trying to chain lenses (functional references) and this problem comes up when I'm dealing with inheritance hierarchies.
Implicit-casts are set to false so I'm expecting some kind of safety there, but I'm not sure if this scenario is just something that I have to somehow be careful about?
I'd at least expect that that program would not compile, but instead, it crashes on the print call.

Is there a way to deal with this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions