Skip to content

Analyzer doesn't throw errors when passing parameter with supertype to functions. #35785

Closed
@Means88

Description

@Means88

Dart VM version: 2.1.0 (Tue Nov 13 18:22:02 2018 +0100) on "macos_x64"
dartanalyzer version 2.1.0

void stringListFunction(List<String> list) {}

void genericListFunction<T>(List<T> list) {}

void stringFunction(String s) {}

main() {
  final List<String> list = ['a', 'b'];
  final Iterable<String> iterable = list.map((item) => item);
  final Object object = {};

  stringListFunction(iterable);
  stringListFunction(object);
  stringFunction(object);
}
➜ dartanalyzer main.dart
Analyzing main.dart...
No issues found!
➜ dart main.dart
Unhandled exception:
type 'MappedListIterable<String, String>' is not a subtype of type 'List<String>'
#0      main (file:///Users/means88/code/test/main.dart:12:22)
#1      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:289:19)
#2      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:171:12)

Metadata

Metadata

Assignees

No one assigned

    Labels

    closed-as-intendedClosed as the reported issue is expected behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions