Skip to content

Commit

Permalink
Issue 50045. Special case bool.fromEnvironment('dart.library.js_util'…
Browse files Browse the repository at this point in the history
…) to return unknown.

Ideally, all `bool.fromEnvironment()` should return "unknown".
But we have issues with making it to be compatible with Andular Dart.
At least at the moment.
So, to unblock Flutter people working on a new platform, we need this.

Bug: #50045
Change-Id: I088a5b822f495d7258ceb1fdeee8f0b8a6a9e120
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261180
Reviewed-by: Brian Wilkerson <[email protected]>
Commit-Queue: Konstantin Shcheglov <[email protected]>
  • Loading branch information
scheglov authored and Commit Queue committed Sep 26, 2022
1 parent aa79371 commit 2e380ff
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/analyzer/lib/src/dart/constant/evaluation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,14 @@ class _InstanceCreationEvaluator {
String? variableName =
argumentCount < 1 ? null : firstArgument?.toStringValue();
if (definingClass == typeProvider.boolElement) {
// Special case: https://github.com/dart-lang/sdk/issues/50045
if (variableName == 'dart.library.js_util') {
return DartObjectImpl(
typeSystem,
typeProvider.boolType,
BoolState.UNKNOWN_VALUE,
);
}
return FromEnvironmentEvaluator(typeSystem, _declaredVariables)
.getBool2(variableName, _namedValues, _constructor);
} else if (definingClass == typeProvider.intElement) {
Expand Down
12 changes: 12 additions & 0 deletions pkg/analyzer/test/generated/constant_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ class ConstantEvaluatorTest extends PubPackageResolutionTest {
await _assertValueInt(74 ^ 42, "74 ^ 42");
}

/// See https://github.com/dart-lang/sdk/issues/50045
test_bool_fromEnvironment_dartLibraryJsUtil() async {
await resolveTestCode('''
const x = bool.fromEnvironment('dart.library.js_util');
''');

_assertTopVarConstValue('x', r'''
bool <unknown>
variable: self::@variable::x
''');
}

test_conditionalExpression_unknownCondition_dynamic() async {
await assertErrorsInCode('''
const bool kIsWeb = identical(0, 0.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class DartObjectPrinter {
),
);
sink.writeln(' <unknown>');
} else if (type.isDartCoreBool) {
sink.write('bool ');
sink.writeln(object.toBoolValue());
} else if (type.isDartCoreDouble) {
sink.write('double ');
sink.writeln(object.toDoubleValue());
Expand Down

0 comments on commit 2e380ff

Please sign in to comment.