Skip to content

Analyzer issue with complex generic functions #33159

Closed
@kevmoo

Description

@kevmoo

Expected: all good. Runs fine, even w/ --preview-dart-2
Actual:

  error • The argument type '(<S₀>(String, (Object) → S) → S₀) → Config' can't be assigned to the parameter type '(<S>(String, (Object) → S) → S) → Config' at lib/_testHarness.dart:7:23 • argument_type_not_assignable
  error • The return type 'int' isn't a 'S', as defined by anonymous closure at lib/_testHarness.dart:7:67 • return_of_invalid_type_from_closure
class Config {
  final int value;
  Config(this.value);
}

Config fromJson(Map json) =>
    checkMethod(json, (check) => new Config(check('value', (v) => v as int)));

typedef _CheckedConvert = S Function<S>(String key, _CastFunction<S>);

typedef _CastFunction<R> = R Function(Object);

T checkMethod<T>(
  Map map,
  T constructor(_CheckedConvert converter),
) {
  Q _checkedConvert<Q>(String key, _CastFunction<Q> castFunc) {
    return castFunc(map[key]);
  }

  return constructor(_checkedConvert);
}

CC @leafpetersen – I'll let you clean-up the labels

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions