Skip to content

Commit 848638c

Browse files
kallentuCommit Queue
authored and
Commit Queue
committed
[analyzer] Add test for enum equality in constant evaluation.
Confirm that const enum equality works with the addition of enum comparisons in recent language changes like dart-lang/language#312 We can keep an extra test in the suite. Fixes #45441 Bug: #45441 Change-Id: I80f7496e172a9a09e9bec3ea1643811788b38443 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/316701 Commit-Queue: Kallen Tu <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 6d4573a commit 848638c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pkg/analyzer/test/src/dart/constant/evaluation_test.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,6 +3190,33 @@ A
31903190
''');
31913191
}
31923192

3193+
test_assertInitializer_enum_false() async {
3194+
await assertErrorsInCode('''
3195+
enum E { a, b }
3196+
class A {
3197+
const A(E e) : assert(e != E.a);
3198+
}
3199+
const c = const A(E.a);
3200+
''', [
3201+
error(CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION, 73, 12),
3202+
]);
3203+
}
3204+
3205+
test_assertInitializer_enum_true() async {
3206+
await assertNoErrorsInCode('''
3207+
enum E { a, b }
3208+
class A {
3209+
const A(E e) : assert(e != E.a);
3210+
}
3211+
const c = const A(E.b);
3212+
''');
3213+
final result = _topLevelVar('c');
3214+
assertDartObjectText(result, '''
3215+
A
3216+
variable: self::@variable::c
3217+
''');
3218+
}
3219+
31933220
test_assertInitializer_intInDoubleContext_assertIsDouble_true() async {
31943221
await assertErrorsInCode('''
31953222
class A {

0 commit comments

Comments
 (0)