Skip to content

Stream<Y implements X> cannot be consumed by StreamConsumer<X> #37179

Closed
@thosakwe

Description

@thosakwe
  • Dart VM version: 2.3.2-dev.0.1 (Tue Jun 4 10:56:51 2019 +0200) on "macos_x64"

It seems that in newer versions of Dart, if I have a Stream<Uint8List>, I cannot use it with a StreamConsumer<List<int>>. This worked in the past, and in my head makes sense - because Uint8List is a descendant of List<int>, anything that accepts a List<int> should accept a Uint8List.

I've included two examples here:
https://github.com/thosakwe/uint8_repro/tree/master/bin

  error • The argument type 'AConsumer' can't be assigned to the parameter type 'StreamConsumer<B>' at bin/general_case.dart:16:21 • argument_type_not_assignable
  error • The argument type 'IntListConsumer' can't be assigned to the parameter type 'StreamConsumer<Uint8List>' at bin/uint8_list.dart:22:29 • argument_type_not_assignable

Both cases result in an argument_type_not_assignable error.


  • Why did this work before? A downcast from Uint8List to List<int> was already illegal in the analyzer before.
  • When were these semantics changed? I didn't see it in the changelog, and this worked as recently as Dart 2.2.0.
  • Stream.pipe is not very useful without support for polymorphism. I can also imagine that this change could break code for a lot of Dart users. For example, I ran into this error while reading files from package:file (using File.openRead), and piping the resulting stream to a StreamConsumer<List<int>>. In [email protected], Uint8List is now returned instead of List<int>, and so anyone depending on that package (20 other packages on Pub) might already be running into this.

Thanks in advance.

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