You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
The issue is illustrated in this code snippet:
class Foo {
String? _string;
Foo() : _string = '';
String doSomething() {
return _string==null ? '' : _string; // => ERROR: A value of type String? cannot be returned...
}
String doSomething2(String? string) {
return string==null ? '' : string;
}
}
In doSomething(), the compiler issues an error: 'A value of type String? cannot be returned from method 'doSomething' because if has return type of String.
I don't understand why, because I have handled nullity with the test.
In addition, the same example is working if I get the input String? as parameter, and do not use the member (see doSomething2())
I have Dart 2.12.0-29.10.beta.
The text was updated successfully, but these errors were encountered:
As @mnordine says, this is expected behavior. You do not get type promotion on fields, only on local variables.
We are aware that this can be highly confusing, but we have also not been able to find a solution within the current language which isn't either unsound or potentially more confusing (because it might only work some of the time anyway, and now you have a more complex job to figure out why).
Hello,
The issue is illustrated in this code snippet:
In doSomething(), the compiler issues an error: 'A value of type String? cannot be returned from method 'doSomething' because if has return type of String.
I don't understand why, because I have handled nullity with the test.
In addition, the same example is working if I get the input String? as parameter, and do not use the member (see doSomething2())
I have Dart 2.12.0-29.10.beta.
The text was updated successfully, but these errors were encountered: