mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 10:49:00 +00:00
Don't report CONST_EVAL_TYPE_BOOL_NUM_STRING for the right operand.
It is not required by the specification. Change-Id: I65863df55194d441885436b8a811858815a3d957 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286060 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
f0fb9db6c8
commit
7b583f2052
2 changed files with 87 additions and 30 deletions
|
@ -66,7 +66,6 @@ class BoolState extends InstanceState {
|
|||
|
||||
@override
|
||||
BoolState equalEqual(TypeSystemImpl typeSystem, InstanceState rightOperand) {
|
||||
assertBoolNumStringOrNull(rightOperand);
|
||||
return isIdentical(typeSystem, rightOperand);
|
||||
}
|
||||
|
||||
|
@ -1471,7 +1470,6 @@ class GenericState extends InstanceState {
|
|||
|
||||
@override
|
||||
BoolState equalEqual(TypeSystemImpl typeSystem, InstanceState rightOperand) {
|
||||
assertBoolNumStringOrNull(rightOperand);
|
||||
return isIdentical(typeSystem, rightOperand);
|
||||
}
|
||||
|
||||
|
@ -1576,18 +1574,6 @@ abstract class InstanceState {
|
|||
}
|
||||
}
|
||||
|
||||
/// Throw an exception if the given [state] does not represent a boolean,
|
||||
/// numeric, string or null value.
|
||||
void assertBoolNumStringOrNull(InstanceState state) {
|
||||
if (!(state is BoolState ||
|
||||
state is NumState ||
|
||||
state is StringState ||
|
||||
state is NullState)) {
|
||||
throw EvaluationException(
|
||||
CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING);
|
||||
}
|
||||
}
|
||||
|
||||
/// Throw an exception if the given [state] does not represent an integer or
|
||||
/// null value.
|
||||
void assertIntOrNull(InstanceState state) {
|
||||
|
@ -2416,7 +2402,6 @@ class ListState extends InstanceState {
|
|||
|
||||
@override
|
||||
BoolState equalEqual(TypeSystemImpl typeSystem, InstanceState rightOperand) {
|
||||
assertBoolNumStringOrNull(rightOperand);
|
||||
return isIdentical(typeSystem, rightOperand);
|
||||
}
|
||||
|
||||
|
@ -2494,7 +2479,6 @@ class MapState extends InstanceState {
|
|||
|
||||
@override
|
||||
BoolState equalEqual(TypeSystemImpl typeSystem, InstanceState rightOperand) {
|
||||
assertBoolNumStringOrNull(rightOperand);
|
||||
return isIdentical(typeSystem, rightOperand);
|
||||
}
|
||||
|
||||
|
@ -2556,7 +2540,6 @@ class NullState extends InstanceState {
|
|||
|
||||
@override
|
||||
BoolState equalEqual(TypeSystemImpl typeSystem, InstanceState rightOperand) {
|
||||
assertBoolNumStringOrNull(rightOperand);
|
||||
return isIdentical(typeSystem, rightOperand);
|
||||
}
|
||||
|
||||
|
@ -2584,7 +2567,6 @@ abstract class NumState extends InstanceState {
|
|||
|
||||
@override
|
||||
BoolState equalEqual(TypeSystemImpl typeSystem, InstanceState rightOperand) {
|
||||
assertBoolNumStringOrNull(rightOperand);
|
||||
return isIdentical(typeSystem, rightOperand);
|
||||
}
|
||||
}
|
||||
|
@ -2761,7 +2743,6 @@ class SetState extends InstanceState {
|
|||
|
||||
@override
|
||||
BoolState equalEqual(TypeSystemImpl typeSystem, InstanceState rightOperand) {
|
||||
assertBoolNumStringOrNull(rightOperand);
|
||||
return isIdentical(typeSystem, rightOperand);
|
||||
}
|
||||
|
||||
|
@ -2838,7 +2819,6 @@ class StringState extends InstanceState {
|
|||
|
||||
@override
|
||||
BoolState equalEqual(TypeSystemImpl typeSystem, InstanceState rightOperand) {
|
||||
assertBoolNumStringOrNull(rightOperand);
|
||||
return isIdentical(typeSystem, rightOperand);
|
||||
}
|
||||
|
||||
|
@ -2900,7 +2880,6 @@ class SymbolState extends InstanceState {
|
|||
|
||||
@override
|
||||
BoolState equalEqual(TypeSystemImpl typeSystem, InstanceState rightOperand) {
|
||||
assertBoolNumStringOrNull(rightOperand);
|
||||
return isIdentical(typeSystem, rightOperand);
|
||||
}
|
||||
|
||||
|
@ -2954,7 +2933,6 @@ class TypeState extends InstanceState {
|
|||
|
||||
@override
|
||||
BoolState equalEqual(TypeSystemImpl typeSystem, InstanceState rightOperand) {
|
||||
assertBoolNumStringOrNull(rightOperand);
|
||||
return isIdentical(typeSystem, rightOperand);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,28 +15,107 @@ main() {
|
|||
|
||||
@reflectiveTest
|
||||
class ConstEvalTypeBoolNumStringTest extends PubPackageResolutionTest {
|
||||
test_equal() async {
|
||||
test_equal_double_object() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
const a = 0.1;
|
||||
const b = a == Object();
|
||||
''');
|
||||
}
|
||||
|
||||
test_equal_int_object() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
const a = 0;
|
||||
const b = a == Object();
|
||||
''');
|
||||
}
|
||||
|
||||
test_equal_int_userClass() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
class A {
|
||||
const A();
|
||||
}
|
||||
|
||||
const num a = 0;
|
||||
const b = a == const A();
|
||||
const a = 0;
|
||||
const b = a == A();
|
||||
''');
|
||||
}
|
||||
|
||||
test_notEqual() async {
|
||||
test_equal_null_object() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
const a = null;
|
||||
const b = a == Object();
|
||||
''');
|
||||
}
|
||||
|
||||
test_equal_string_object() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
const a = 'foo';
|
||||
const b = a == Object();
|
||||
''');
|
||||
}
|
||||
|
||||
test_equal_userClass_int() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A {
|
||||
const A();
|
||||
}
|
||||
|
||||
const num a = 0;
|
||||
const _ = a != const A();
|
||||
const a = A();
|
||||
const b = a == 0;
|
||||
''', [
|
||||
error(HintCode.UNUSED_ELEMENT, 49, 1),
|
||||
error(CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING, 53, 14),
|
||||
error(CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING, 51, 6),
|
||||
]);
|
||||
}
|
||||
|
||||
test_notEqual_double_object() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
const a = 0.1;
|
||||
const b = a != Object();
|
||||
''');
|
||||
}
|
||||
|
||||
test_notEqual_int_object() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
const a = 0;
|
||||
const b = a != Object();
|
||||
''');
|
||||
}
|
||||
|
||||
test_notEqual_int_userClass() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
class A {
|
||||
const A();
|
||||
}
|
||||
|
||||
const a = 0;
|
||||
const b = a != A();
|
||||
''');
|
||||
}
|
||||
|
||||
test_notEqual_null_object() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
const a = null;
|
||||
const b = a != Object();
|
||||
''');
|
||||
}
|
||||
|
||||
test_notEqual_string_object() async {
|
||||
await assertNoErrorsInCode(r'''
|
||||
const a = 'foo';
|
||||
const b = a != Object();
|
||||
''');
|
||||
}
|
||||
|
||||
test_notEqual_userClass_int() async {
|
||||
await assertErrorsInCode(r'''
|
||||
class A {
|
||||
const A();
|
||||
}
|
||||
|
||||
const a = A();
|
||||
const b = a != 0;
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_NUM_STRING, 51, 6),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue