Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly type Stream argument as List<int> #56

Merged
merged 2 commits into from
Jul 6, 2023
Merged

Commits on Jul 6, 2023

  1. Explicitly type Stream argument as List<int>

    A breaking change (see [0]) will make `utf8.encode()` return the more precise
    `Uint8List` type (instead of the current `List<int>`).
    
    In rare circumstances this can lead to changes in behavior, mainly when
    code relies on type inference, a different type got inferred and the code
    dependend on the type not being inferred a more precise type.
    
    Here we explicitly use `Stream<List<int>>` instead of relying on type
    inference (which would infer `Stream<Uint8List>` in some cases after
    [0]). This is necessary as the stream transformer APIs cannot work with
    subtypes. Example of code that fails at runtime:
    
    ```
      import 'dart:typed_data';
      import 'dart:convert';
    
      void main() {
        Stream<Uint8List> stream = Stream.fromIterable([]);
        Stream<List<int>> stream2 = stream;
        stream2.transform(utf8.decoder);
             //  ^^^ Will throw due to Utf8Decoder not being subtype of
             //      StreamTransformer<Uint8List, String>.
      }
    ```
    
    [0] dart-lang/sdk#52801
    mkustermann committed Jul 6, 2023
    Configuration menu
    Copy the full SHA
    d65a3bc View commit details
    Browse the repository at this point in the history
  2. Update pubspec and changelog

    nex3 committed Jul 6, 2023
    Configuration menu
    Copy the full SHA
    4d852ca View commit details
    Browse the repository at this point in the history