Skip to content

Generic function type as a type argument of the generic function type alias works incorrectly. #45313

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
iarkh opened this issue Mar 15, 2021 · 5 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. 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

@iarkh
Copy link
Contributor

iarkh commented Mar 15, 2021

Dart SDK version: 2.13.0-114.0.dev (dev) (Sat Mar 6 18:27:50 2021 -0800) on "windows_x64"

The following code example declares generic function typedef TEST_TYPEDEF and then try to assign TEST_TYPEDEF variable and check its type:

typedef TEST_TYPEDEF<TT extends T Function<T>(T)> = void Function<TTT extends TT>();
void  testme<TT extends T Function<T>(T)>() {}

main() {
  print(testme is TEST_TYPEDEF);
  TEST_TYPEDEF ttttt = testme;
  print(ttttt is TEST_TYPEDEF);
}

It's expected that if I succssffully assign testme to the variable of the type TEST_TYPEDEF, ttttt is TEST_TYPEDEF should report true. However, this is not so here: there are no errors and the example above twice prints false unexpectidly.

@eernstg eernstg added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Mar 15, 2021
@eernstg
Copy link
Member

eernstg commented Mar 15, 2021

Agreed, TEST_TYPEDEF means TEST_TYPEDEF<T Function<T>(T)> means void Function<TTT extends T Function<T>(T)>(), same as void Function<TT extends T Function<T>(T)>(), so we should get true, twice.

library /*isNonNullableByDefault*/;
import self as self;
import "dart:core" as core;

typedef TEST_TYPEDEF<invariant TT extends <T extends core::Object? = dynamic>(T%) → T% = <T extends core::Object? = dynamic>(T%) → T%> = <TTT extends TT = dynamic>() → void;
static method testme<TT extends <T extends core::Object? = dynamic>(T%) → T% = <T extends core::Object? = dynamic>(T%) → T%>() → void {}
static method main() → dynamic {
  core::print((#C1) is{ForNonNullableByDefault} <TTT extends <T extends core::Object? = dynamic>(T%) → T% = dynamic>() → void);
  <TTT extends <T extends core::Object? = dynamic>(T%) → T% = dynamic>() → void ttttt = #C1;
  core::print(ttttt is{ForNonNullableByDefault} <TTT extends <T extends core::Object? = dynamic>(T%) → T% = dynamic>() → void);
}
constants  {
  #C1 = tearoff self::testme
}

@johnniwinther, does this look like a front-end issue? I suspect it's a vm issue, but TTT extends TT = dynamic looks a bit surprising to me.

@a-siva
Copy link
Contributor

a-siva commented Mar 15, 2021

//cc @crelier

@a-siva a-siva added legacy-area-front-end Legacy: Use area-dart-model instead. area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on labels Mar 15, 2021
@chloestefantsova
Copy link
Contributor

@eernstg I think the suspicious TTT extends TT = dynamic part is because the default types (those the follow = in the declarations of type variables) don't really make sense for function types, only for classes and functions, because instantiate-to-bound doesn't apply to them. We see them there only because we use the same TypeParameter node kind for all of class, function, typedef, and function type type parameters. It likely doesn't affect the execution.

@eernstg
Copy link
Member

eernstg commented Mar 16, 2021

OK, thanks!

@johnniwinther johnniwinther removed the legacy-area-front-end Legacy: Use area-dart-model instead. label Mar 16, 2021
@johnniwinther
Copy link
Member

I don't think it's a front end issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. 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

6 participants