Skip to content

Dart does not throw compile time error when wrong type is assigned to a variable using the if null operator (??) #36964

Closed
@gtrochimiuk

Description

@gtrochimiuk

Dart VM version: 2.3.0-dev.0.5.flutter-a1668566e5 (Tue Apr 30 20:35:41 2019 +0200) on "macos_x64"

Dart does not throw compile time error when wrong type is assigned to a variable if you use the "if null" operator. Following example compiles without error and then throws a runtime error:

class ExampleClass {}

void main() {
  ExampleClass example = 'string' ?? ExampleClass();
}

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