Skip to content

[Analyzer] null-safe no warning or compilation error for Completer.complete() #45319

@bitsydarel

Description

@bitsydarel

This tracker is for issues related to:

  • Analyzer

  • Dart SDK Version (dart --version)
    Dart SDK version: 2.12.0 (stable) (Thu Feb 25 19:50:53 2021 +0100) on "macos_x64"

Dart analyzer don't provide warning or compilation error when Map<String, Completer> is passed to a function with argument Map<String, Completer<Object?>>. But throws a error at runtime which basically remove all the benefits of a null/type safe code.

As you can see Completer is not equal to Completer<Object?>

code to replicate:

import 'dart:async';

void main() {
  final Map<String, Completer<Object>> tracker = <String, Completer<Object>>{
    '1': Completer(),
    '2': Completer(),
    '3': Completer(),
  };

  allCompleted(tracker);
  
  // trows Uncaught Error: TypeError: null: type 'Null' is not a subtype of type 'Object'
  tracker['2']?.complete();
  
  allCompleted(tracker);
}

void allCompleted(final Map<String, Completer<Object?>> tracker) {
  tracker.forEach(
    (key, completer) => print("${key} is completed ${completer.isCompleted}"),
  );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work ondevexp-warningIssues with the analyzer's Warning codeslegacy-area-analyzerUse area-devexp instead.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions