Skip to content

Analyzer: Issues with inherited parameter types that include generic function types #31804

@MichaelRFairhurst

Description

@MichaelRFairhurst

When inheriting parameter types ie:

class Base {
  void f(int x);
}

class Sub extends Base {
  f(x); // type of `x` inherited from `Base.f`
}

The inherited type may be a generic function. This leads to confusion in the element model because the enclosing type parameter contexts are assumed to be a discoverable via enclosingElement.

This means, given

class Base {
  void f(void Function<T>(T) x);
}

class Sub extends Base {
  f(x); // the type of `x` inherited from `Base.f`
}

the FunctionType from x must get a new synthetic Element so that its parameter T can be enclosed within the Sub class.

This is currently working in the above example, but not in more complex examples such as:

  void f(List<void Function<T>(T)> x);

in which case the FunctionTypeElement is not copied into a synthetic when f is overriden without a parameter type annotation, leading to a crash at deserialization time from summaries.

This may also affect other cases:

typedef F = Function<T>();
...
  void f(List<F> fs);
// or
  void f(Function(Function<T>()) x);

etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onanalyzer-apiIssues that impact the public API of the analyzer packagearea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions