mirror of
https://github.com/dart-lang/sdk
synced 2024-10-05 00:25:11 +00:00
When const evaluating ConditionalExpression, if the condition is unknown, checks both then/else for errors.
Bug: https://github.com/flutter/flutter/issues/91906 Change-Id: I29057d9b5704fe9850a6ba2ed1416472c7e1abc6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217025 Reviewed-by: Samuel Rawlins <srawlins@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
1aaed6385f
commit
71da05e920
|
@ -80,7 +80,7 @@ import 'package:meta/meta.dart';
|
|||
/// TODO(scheglov) Clean up the list of implicitly analyzed files.
|
||||
class AnalysisDriver implements AnalysisDriverGeneric {
|
||||
/// The version of data format, should be incremented on every format change.
|
||||
static const int DATA_VERSION = 188;
|
||||
static const int DATA_VERSION = 189;
|
||||
|
||||
/// The number of exception contexts allowed to write. Once this field is
|
||||
/// zero, we stop writing any new exception contexts in this process.
|
||||
|
|
|
@ -610,10 +610,15 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
|
|||
if (conditionResult == null) {
|
||||
return conditionResult;
|
||||
}
|
||||
if (conditionResult.toBoolValue() == true) {
|
||||
|
||||
var conditionResultBool = conditionResult.toBoolValue();
|
||||
if (conditionResultBool == null) {
|
||||
node.thenExpression.accept(this);
|
||||
node.elseExpression.accept(this);
|
||||
} else if (conditionResultBool == true) {
|
||||
_reportNotPotentialConstants(node.elseExpression);
|
||||
return node.thenExpression.accept(this);
|
||||
} else if (conditionResult.toBoolValue() == false) {
|
||||
} else if (conditionResultBool == false) {
|
||||
_reportNotPotentialConstants(node.thenExpression);
|
||||
return node.elseExpression.accept(this);
|
||||
}
|
||||
|
|
|
@ -1393,6 +1393,22 @@ class C {}
|
|||
errorCodes: [CompileTimeErrorCode.INVALID_CONSTANT]);
|
||||
}
|
||||
|
||||
test_visitConditionalExpression_lazy_unknown_int_invalid() async {
|
||||
await resolveTestCode('''
|
||||
const c = identical(0, 0.0) ? 1 : new Object();
|
||||
''');
|
||||
_evaluateConstantOrNull('c',
|
||||
errorCodes: [CompileTimeErrorCode.INVALID_CONSTANT]);
|
||||
}
|
||||
|
||||
test_visitConditionalExpression_lazy_unknown_invalid_int() async {
|
||||
await resolveTestCode('''
|
||||
const c = identical(0, 0.0) ? 1 : new Object();
|
||||
''');
|
||||
_evaluateConstantOrNull('c',
|
||||
errorCodes: [CompileTimeErrorCode.INVALID_CONSTANT]);
|
||||
}
|
||||
|
||||
test_visitIntegerLiteral() async {
|
||||
await resolveTestCode('''
|
||||
const double d = 3;
|
||||
|
|
Loading…
Reference in a new issue