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

Different tear-offs are wrongly identical in analyzer #47267

Closed
sgrekhov opened this issue Sep 22, 2021 · 1 comment
Closed

Different tear-offs are wrongly identical in analyzer #47267

sgrekhov opened this issue Sep 22, 2021 · 1 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. P2 A bug or feature request we're likely to work on

Comments

@sgrekhov
Copy link
Contributor

Consider the following code

class CheckIdentical {
  const CheckIdentical(Object? o1, Object? o2) : assert(identical(o1, o2));
}

typedef MyList<T extends num> = List<T>;

main() {
  const v1 = MyList<int>.filled;
  const v2 = MyList<int>.filled;
  const v3 = (MyList.filled)<int>;

  const CheckIdentical(v1, v2);
  const CheckIdentical(v1, v3); // Error in VM here (Error: Constant evaluation error), no issues in analyzer
}

According to @eernstg MyList is not a proper rename, so if we tear off a generic function then it gets the identity for MyList, and it's never identical to any tearoff of a List constructor.

However, when we pass actual type arguments in the tearoff, we get the fully expanded type alias (whether or not it's a proper rename, that doesn't matter). That is, MyList<int>.filled is identical to List<int>.filled.

So we should expect that v1 and v2 are identical, but v1 and v3 are not identical, so there's an issue for the analyzer.

@sgrekhov sgrekhov added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Sep 22, 2021
@srawlins srawlins added analyzer-spec Issues with the analyzer's implementation of the language spec P2 A bug or feature request we're likely to work on labels Sep 28, 2021
@eernstg
Copy link
Member

eernstg commented Oct 12, 2021

Perhaps the issue would be a bit easier to read if the code is changed to have const CheckNotIdentical(v1, v3), such that the program succeeds with a tool that behaves as specified.

copybara-service bot pushed a commit that referenced this issue Nov 10, 2021
An alternative to https://dart-review.googlesource.com/c/sdk/+/218582

In the case of a constructor tear-off through a non-proper rename type
alias, we store the type alias on the FunctionState in constant
evaluation.

Fixes #47267

Change-Id: I3bcbc11fceafc3a688eb956cf0459ad1dbde6307
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/218746
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Samuel Rawlins <[email protected]>
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. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

3 participants