Skip to content

Analyzer allows calling record with call field as a function #54651

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

Open
lrhn opened this issue Jan 17, 2024 · 1 comment
Open

Analyzer allows calling record with call field as a function #54651

lrhn opened this issue Jan 17, 2024 · 1 comment
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec feature-records Implementation of the records feature P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@lrhn
Copy link
Member

lrhn commented Jan 17, 2024

(Split from #54616 since it's not expected to be due to shared code.)

Example:

void main() {
  var c = (call: (int x) => x);
  var v = c(1);
  Chk(v).staticType<E<int>>(); // CFE accepts if type is `int`.
  Chk(v).staticType<E<dynamic>>();  // Analyzer accepts if type is `dynamic`.

  var c2 = (call: intId);
  var v2 = c2(1);
  Chk(v2).staticType<E<int>>();

  var c3 = (call: <T>(T x) => x);
  var v3a = c3(1);
  Chk(v3a).staticType<E<int>>();
  var v3b = c3("a");
  Chk(v3b).staticType<E<String>>();
}

int intId(int x) => x;

class Chk<T> {
  const Chk(T value);
  void staticType<X extends E<T>>() {}
}
typedef E<T> = void Function<StaticType extends T>();

Both c(1) and c2(1) should be compile-time errors since their static type is not a function type,
and it's not a type which has a call method. It has a call getter, but that's not sufficient to allow a .call insertion to be performed.

The analyzer allows it, but then doesn't know what to do about it, so the type of the call ends up as dynamic.
The front-end allows it and gives the return type of the function (#54616).

See: dart-lang/language#3558

@lrhn lrhn added legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) feature-records Implementation of the records feature labels Jan 17, 2024
@lrhn lrhn changed the title Analyzer allow calling record with call field as a functionCreate an issue Analyzer allows calling record with call field as a function Jan 17, 2024
@pq pq added dart-model-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 Jan 17, 2024
@srawlins
Copy link
Member

Still an issue.

@bwilkerson bwilkerson added area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. and removed legacy-area-analyzer Use area-devexp instead. labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec feature-records Implementation of the records feature P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants