Skip to content

Handle nullable in string concatenation #2268

Closed
@asashour

Description

@asashour
void f(int? i) {
  var s1 = '' + i;

  var s2 = '$i';
}

It is currently not allowed to assign a nullable (int, String, etc.) to a String as required by the concatenation +.

However, interpolation handles it gracefully.

Would it make sense to also handle it in concatenation, after the +, or even before (if detected as concatenation)?

So the below would be allowed:

void f(String? s) {
  var s1 = s + s;

  var s2 = '$s$s';
}

I know that interpolation is the preferred way, but as concatenation is there, I guess it would make the language a little smarter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    requestRequests to resolve a particular developer problem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions