Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyzer: Improperly failed inference with promoted type parameters #35799

Open
MichaelRFairhurst opened this issue Jan 29, 2019 · 6 comments
Open
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@MichaelRFairhurst
Copy link
Contributor

MichaelRFairhurst commented Jan 29, 2019

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

@MichaelRFairhurst MichaelRFairhurst added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jan 29, 2019
@stereotype441
Copy link
Member

Note: there is a test in the analyzer codebase that should be re-enabled when this bug is fixed: https://dart-review.googlesource.com/c/sdk/+/90880/4/pkg/analyzer/test/src/task/strong/checker_test.dart#3989

@srawlins srawlins added the analyzer-spec Issues with the analyzer's implementation of the language spec label Jun 17, 2020
@srawlins srawlins added P3 A lower priority bug or feature request and removed P2 A bug or feature request we're likely to work on labels Apr 18, 2023
@eernstg
Copy link
Member

eernstg commented Apr 18, 2023

I'm not convinced that this issue should be considered as a bug in the analyzer, it is probably about the type inference algorithm. I created dart-lang/language#3009 for that.

@FMorschel
Copy link
Contributor

So, just to help out a bit, as for what I found:

#52077
#52117
#56028 (this is potentially the solution for the other two)

Are all possibly related?

@eernstg
Copy link
Member

eernstg commented Apr 20, 2023

@FMorschel, thanks for looking into those potential connections!

I do think there is a connection between #52117 and #52077 and #56028, they are all about extensions and intersection types.

However, there is probably no connection to this issue, where the topic is F-bounded type variables and inference (with no references to intersection types or extensions at all).

@FMorschel
Copy link
Contributor

Sorry about my ignorance. I just thought they were connected because in #52117 there is also a suggestion in #52117 that sounded to me similar to this issue.

@eernstg
Copy link
Member

eernstg commented Apr 20, 2023

No problem, it is not always easy to see whether or not there is a connection!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants