Skip to content

ARGUMENT_TYPE_NOT_ASSIGNABLE although preceded by a not-null condition #46897

Closed
@asashour

Description

@asashour

For the below case, there is a compiler error

The argument type 'TypeAnnotation?' can't be assigned to the parameter type 'AstNode'

I believe this shouldn't happen, since there is a check for returnType != null, also the error is removed if the returnType is declared as

var returnType = function?.returnType;
void fun(FunctionDeclaration? function, ChangeBuilder builder, String file) async {
  TypeAnnotation? returnType;
  returnType = function?.returnType;
  // var returnType = function?.returnType; // this doesn't give an error

  if (returnType != null) {
    await builder.addDartFileEdit(file, (builder) {
      builder.addReplacement(range.node(returnType), (builder) {
        //                              ^^^^^^^^^^ error is here
      });
    });
  }
}

Dart SDK version: 2.15.0-6.0.dev (dev) (Wed Aug 11 14:48:30 2021 -0700) on "windows_x64"

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions