dart-lang / collection

The collection package for Dart contains a number of separate libraries with utility functions and classes that makes working with collections easier.

Home Page:https://pub.dev/packages/collection

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CanonicalizedMap.cast() throws _CastError

bobjackman opened this issue · comments

CanonicalizedMap.cast() throws _CastError

Example:

try {
  var sourceMap     = <String, String>{'a': 'A'};
  var canonicalized = new CanonicalizedMap<String, String, String>.from(sourceMap, (String key) => key.toLowerCase());
    
  var badResult     = canonicalized.cast<String, String>();
  var goodResult    = Map.of(canonicalized).cast<String, String>();

  print(goodResult); // {a: A}
  print(badResult ); // _CastError: type 'MapEntry<String, String>' is not a subtype of type 'String' in type cast

} catch(e, s) {
  print('Unhandled Exception: ${e.runtimeType}: $e\n$s');
}

Expected Result:

Calling .cast() should not throw in this circumstance