Skip to content

[pigeon] "decode" casts fail in sound null-safe mode. #76405

@ditman

Description

@ditman

Here's a Pigeon-generated class:

class PositionMessage {
  int? textureId;
  int? position;

  Object encode() {
    final Map<Object?, Object?> pigeonMap = <Object?, Object?>{};
    pigeonMap['textureId'] = textureId;
    pigeonMap['position'] = position;
    return pigeonMap;
  }

  static PositionMessage decode(Object message) {
    final Map<Object?, Object?> pigeonMap = message as Map<Object?, Object?>;
    return PositionMessage()
      ..textureId = pigeonMap['textureId'] as int
      ..position = pigeonMap['position'] as int;
  }
}

In sound null-safe mode, the decode method might have null values in textureId and position, so the cast as int fails:

type 'Null' is not a subtype of type 'int' in type cast
  package:video_player_platform_interface/messages.dart 121:44  PositionMessage.decode
  package:video_player_platform_interface/messages.dart 339:30  VideoPlayerApi.position

Shouldn't the as casts match the type of the attribute they're casting to? if int? textureId, shouldn't the decode cast to: as int?

Steps to Reproduce

Attempt to run the video_player_platform_interface tests in null-safe mode (flutter channel master, for example):

  1. Clone this branch: https://github.com/ditman/plugins/tree/reversion-video_player_platform_interface-as-preview
  2. cd YOUR_CLONE/packages/video_player/video_player_platform_interface
  3. flutter test

Expected results:

All tests pass.

Actual results:

Some tests fail with the error described in this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: null-safetySupport for Dart's null safety featurea: tests"flutter test", flutter_test, or one of our testsp: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions