Skip to content

Pattern match missing inference and generic method instantiation #51871

Closed
@nshahan

Description

@nshahan

A missing generic instantiation is causing a compile time error here:

void testRelational() {
const c = id;
// Instantiates based on the context type of the "<" method parameter type.
if (Compare() case < c) {
Expect.fail('"<" should receive instantiation, not generic function.');
} else {
// OK.
}
}

org-dartlang-app:/tests/language/patterns/implicit_instantiation_test.dart:36:24: Error: The argument type 'T Function<T>(T)' can't be assigned to the parameter type 'int Function(int)'.
  if (Compare() case < c) {
                       ^

In a discussion with @munificent he mentioned that this pattern match should have the same downward inference and generic instantiation as this similar code that doesn't contain any patterns and runs without any errors:

T id<T>(T t) => t;

typedef IntFn = int Function(int);
typedef TFn = T Function<T>(T);

class Compare {
  operator <(IntFn f) {
    print(f.runtimeType);
    return f is TFn;
  }
}

main() {
  const c = id;
  Compare() < c;
}

cc @johnniwinther

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions