Skip to content

Type parameter bounds can be marked "exact nullable" if upcast. #40551

Closed
@MichaelRFairhurst

Description

@MichaelRFairhurst
class B<T extends Object> {                                                      
  void f(T t) {                                                                  
    // Create an edge from the bound to some type                                
    List<dynamic> x = [t];                                                       
    // and make that type exact nullable                                         
    x[0] = null;                                                                 
  }                                                                              
}

This migration should produce no source edits.

Currently, the assignment from List<T> to List<dynamic> results in an edge from the bound of T to the dynamic type argument in List<dynamic>. This is correct.

But it has an unfortunate consequence, it means that when dynamic is marked exact nullable (by assigning null to the list index), that exact nullability is propagated upstream, and that is currently not stopped in any way from marking the bound of T as exact nullable.

We therefore get T extends Object? whis is unnecessary.

This occurs in package:async.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NNBDIssues related to NNBD ReleaseP3A lower priority bug or feature requestarea-migration (deprecated)Deprecated: this label is no longer actively used (was: issues with the `dart migrate` tool).nnbd-migration-correctness-exampleConcrete examples of the migration engine producing an incorrect result on a phase 1 packagetype-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions