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] Function.call does not get the type Function #54549

Closed
eernstg opened this issue Jan 9, 2024 · 3 comments
Closed

[analyzer] Function.call does not get the type Function #54549

eernstg opened this issue Jan 9, 2024 · 3 comments
Assignees
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. soundness

Comments

@eernstg
Copy link
Member

eernstg commented Jan 9, 2024

Consider the following program:

typedef Exactly<X> = X Function(X);

extension StaticTypeHelper<X> on X {
  X expectStaticType<Y extends Exactly<X>>() => this;
}

void main() {
  Function d = print;
  var f = d.call;
  f.expectStaticType<Exactly<Function>>(); // No error (analyzer and CFE agree).
  int i = f; // No error according to the analyzer.
}

The CFE reports a compile-time error on the initializing expression of the local variable i, but the analyzer accepts the declaration of i with no diagnostic messages (seen in DartPad based on Dart SDK 3.3.0-273.0.dev).

When the insertion point in DartPad is at the declaration of f, the Documentation pane indicates that the type of f is InvalidType (which is probably the reason why no further errors are reported, no matter how f is used).

However, the static type of f should have been Function: https://github.com/dart-lang/language/blob/daf5cbd39e5b23bf7836dfa0926d0cfe4ae663b9/specification/dartLangSpec.tex#L14799.

@eernstg eernstg added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. soundness analyzer-spec Issues with the analyzer's implementation of the language spec labels Jan 9, 2024
@eernstg
Copy link
Member Author

eernstg commented Jan 9, 2024

The soundness issue comes up because there is no compile-time error in the given example program according to the analyzer, but if we actually allow such a program to run (that is, if the CFE also hadn't reported any errors) then we would create a situation where a variable of type int refers to an object of type void Function(Object?), which is a soundness violation.

@bwilkerson
Copy link
Member

@scheglov

@scheglov scheglov self-assigned this Jan 9, 2024
@scheglov
Copy link
Contributor

scheglov commented Jan 9, 2024

@scheglov scheglov closed this as completed Jan 9, 2024
copybara-service bot pushed a commit that referenced this issue Jan 9, 2024
Bug: #54549
Change-Id: I8e64cfc530434af2a26fc6cbf0d22204a1107392
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345364
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
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. soundness
Projects
None yet
Development

No branches or pull requests

3 participants