Skip to content

Strange type comparison for functions #33261

@iarkh

Description

@iarkh
  • Dart SDK Version: 2.0.0-dev.58.0 (Wed May 23 20:44:51 2018 +0200)
  • OS: Windows 10

The following code sample compares type of some Function object with one defined with typedef:

typedef F<X extends int> = void Function(X);
void func(x) {print(x+2);}

typedef F1<X extends int> = X Function();
String func1() {return "3";}

main() {
  print(func is F);
  print(func is F<dynamic>);
  print(func is F<int>);
  print(func is F<String>);

  print("--------------------------");
  print(func1 is F1);
  print(func1 is F1<dynamic>);
  print(func1 is F1<int>);
  print(func1 is F1<String>);
}

Sample output looks strange for me:

$> dart --preview-dart-2 test.dart
true
true
true
true
--------------------------
false
true
false
true

This shows that void func(x) {print(x+2);} is treated as F<String> - this is strange as F should have type argument which extends int (and String does NOT extends it),

At the same time, I see that void func(x) {print(x+2);} is not F1<String>, and it looks expected.

Also it;s not clear why func is F returns true, but func1 is F1 returns `false - should not results be the same here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions