Skip to content

Analyzer: Improperly failed inference with promoted type parameters #35799

Open
@MichaelRFairhurst

Description

@MichaelRFairhurst

Here, the call to f should be valid and inferrable as Cloneable<T>.

class Clonable<T> {}                                                                             
class SubClonable<T> extends Clonable<T> {
  T m(T t) => t;  
} 

void f<T extends Clonable<T>>(T object) {
  if (object is SubClonable<T>) {
    f(object);
  }     
}

However it fails in analyzer and CFE. This is the analyzer ticket for this issue. (CFE is #35800)

It's critical to note that object is promoted to type T' extends SubCloneable<T>. So if the analyzer attempts to infer SubClonable<T> for T in f(object), then that will fail. However, it should be possible to infer Clonable, which in fact works when typed explicitly.

May be related to #35100

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.dart-model-analyzer-specIssues with the analyzer's implementation of the language spectype-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