Description
lib_2/isolate/string_from_environment_default_value_test.dart is failing in the NNBD SDK. Both expectations fail:
Expect.isNull(const String.fromEnvironment('NOT_FOUND'));
Expect.equals('x', const String.fromEnvironment('NOT_FOUND', defaultValue: 'x'));
The failures are because the API was changed to default defaultValue
to an empty string rather than null:
const factory String.fromEnvironment(String name, {String defaultValue = ""})
So the first expect is easily fixed by updating it to expect an empty string rather than null. The second failure is more interesting, and that's what this bug is about.
The issue is that const String.fromEnvironment('NOT_FOUND', defaultValue: 'x')
is returning an empty string even though defaultValue
is given. Some other interesting data points:
- If we remove the
const
modifier, the test passes. I think this means its a const eval bug, and the VM implementation works. - If we remove
= ""
from the method signature, reverting it back to a null default, then the call returns"x"
and the test passes. - If we change
= ""
to something else, like"hi"
, then this string is returned from the call in the test. So that part of the plumbing is working.
My guess is that there's something in the const evaluator that is checking whether the defaultValue is provided by comparing it to null, so the default value of empty string looks like a provided value.