Skip to content

CFE allows calling record with call field as a function. #54616

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

Closed
lrhn opened this issue Jan 13, 2024 · 6 comments
Closed

CFE allows calling record with call field as a function. #54616

lrhn opened this issue Jan 13, 2024 · 6 comments
Assignees
Labels
cfe-dysfunctionalities Issues for the CFE not behaving as intended feature-records Implementation of the records feature legacy-area-front-end Legacy: Use area-dart-model instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@lrhn
Copy link
Member

lrhn commented Jan 13, 2024

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.

See: dart-lang/language#3558

@lrhn lrhn added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) area-fe-analyzer-shared feature-records Implementation of the records feature labels Jan 13, 2024
@lrhn
Copy link
Member Author

lrhn commented Jan 14, 2024

Just read #54351 where it's mentioned that we don't want call getters on records to be callable.

@johnniwinther johnniwinther added the cfe-dysfunctionalities Issues for the CFE not behaving as intended label Jan 15, 2024
@johnniwinther
Copy link
Member

@chloestefantsova Can you take a look at this for the CFE? (I don't think this is done in shared code)

@chloestefantsova
Copy link
Contributor

@chloestefantsova Can you take a look at this for the CFE? (I don't think this is done in shared code)

Sure! Will do.

@lrhn lrhn changed the title Analyzer and CFE allow calling record with call field as a function. allow calling record with call field as a function. Jan 17, 2024
@lrhn lrhn changed the title allow calling record with call field as a function. CFE allows calling record with call field as a function. Jan 17, 2024
@lrhn
Copy link
Member Author

lrhn commented Jan 17, 2024

Since this is (probably) not shared code, I split it into an analyzer issue (#54651), and made this issue CFE-specific.

@lrhn lrhn added legacy-area-front-end Legacy: Use area-dart-model instead. and removed area-fe-analyzer-shared labels Jan 17, 2024
@chloestefantsova chloestefantsova self-assigned this Jan 17, 2024
@chloestefantsova
Copy link
Contributor

Both c(1) and c2(1) should be compile-time errors

Am I right to assume the calls to c(3) should be compile-time errors as well?

@lrhn
Copy link
Member Author

lrhn commented Jan 29, 2024

Yes. A record type is not a callable type since it doesn't have a call method.
Having a call getter doesn't apply, same as for any other type.

(It can accept an extension call method like any other type, if it doesn't have a member base-named call.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cfe-dysfunctionalities Issues for the CFE not behaving as intended feature-records Implementation of the records feature legacy-area-front-end Legacy: Use area-dart-model instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants