From 22f451c4ace57cc853a1cb7df610bba65135471c Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Wed, 3 Jun 2026 11:13:59 -0700 Subject: [PATCH] CQ. Use assertDartObjectText() with raw multi-line string in more places. Replace ad hoc assertions over DartObjectImpl with assertDartObjectText() in constant evaluation and resolution tests. This makes the expected constant value shape explicit, including invalid results, variables, constructor invocations, type arguments, and superclass fields, instead of checking only selected fields. Use raw multi-line strings for these expectations so expected text can be copied and maintained consistently without escaping interpolation or other Dart string syntax. Remove the now-unused null assertion helper and analyzer implementation imports that were only needed by the direct assertions. Change-Id: Ib734c1d428dd69104403484534b60af918944d13 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/508705 Reviewed-by: Paul Berry --- .../src/dart/constant/evaluation_test.dart | 594 +++++++++++------- .../src/dart/resolution/constant_test.dart | 56 +- 2 files changed, 403 insertions(+), 247 deletions(-) diff --git a/pkg/analyzer/test/src/dart/constant/evaluation_test.dart b/pkg/analyzer/test/src/dart/constant/evaluation_test.dart index 87f7c2761aa..08d5b9ee57c 100644 --- a/pkg/analyzer/test/src/dart/constant/evaluation_test.dart +++ b/pkg/analyzer/test/src/dart/constant/evaluation_test.dart @@ -37,7 +37,7 @@ const a = E(42); const x = a as int; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' int 42 variable: ::@topLevelVariable::x typeNotExtensionTypeErased: E @@ -51,7 +51,7 @@ extension type E(int? it) {} const x = null as E; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Null null variable: ::@topLevelVariable::x '''); @@ -62,7 +62,7 @@ Null null const x = null as Never?; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Null null variable: ::@topLevelVariable::x '''); @@ -75,7 +75,7 @@ extension type const E(int it) {} const x = 42 as E; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' int 42 variable: ::@topLevelVariable::x '''); @@ -90,7 +90,7 @@ const b = E(3); const x = (a as num) * (b as num); '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' int 6 variable: ::@topLevelVariable::x '''); @@ -137,7 +137,7 @@ class A { const v = A() == .new(); '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool true variable: ::@topLevelVariable::v '''); @@ -167,7 +167,7 @@ class A { const v = A() == .field; '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool true variable: ::@topLevelVariable::v '''); @@ -226,7 +226,7 @@ class A { const A a = .field; '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' A constructorInvocation constructor: ::@class::A::@constructor::new @@ -425,7 +425,7 @@ E const v = true == false; '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool false variable: ::@topLevelVariable::v '''); @@ -436,7 +436,7 @@ bool false const v = true == true; '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool true variable: ::@topLevelVariable::v '''); @@ -447,7 +447,7 @@ bool true const v = 1.2 == Object(); '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool false variable: ::@topLevelVariable::v '''); @@ -458,7 +458,7 @@ bool false const v = 1 == 2; '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool false variable: ::@topLevelVariable::v '''); @@ -469,7 +469,7 @@ bool false const v = 1 == 1; '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool true variable: ::@topLevelVariable::v '''); @@ -481,7 +481,7 @@ const int? a = 1; const v = a == null; '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool false variable: ::@topLevelVariable::v '''); @@ -492,7 +492,7 @@ bool false const v = 1 == Object(); '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool false variable: ::@topLevelVariable::v '''); @@ -507,7 +507,7 @@ class A { const v = 1 == A(); '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool false variable: ::@topLevelVariable::v '''); @@ -536,7 +536,7 @@ const v = 1 == a; const v = [] == []; '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool true variable: ::@topLevelVariable::v '''); @@ -547,7 +547,7 @@ bool true const v = [1, 2] == [1, 2]; '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool true variable: ::@topLevelVariable::v '''); @@ -558,7 +558,7 @@ bool true const v = const [] == const []; '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool false variable: ::@topLevelVariable::v '''); @@ -569,7 +569,7 @@ bool false const v = {} == {}; '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool true variable: ::@topLevelVariable::v '''); @@ -580,7 +580,7 @@ bool true const v = {'x': 1, 'y': 2} == {'x': 1, 'y': 2}; '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool true variable: ::@topLevelVariable::v '''); @@ -591,7 +591,7 @@ bool true const v = const {} == const {}; '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool false variable: ::@topLevelVariable::v '''); @@ -603,7 +603,7 @@ const Object? a = null; const v = a == Object(); '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool false variable: ::@topLevelVariable::v '''); @@ -614,7 +614,7 @@ bool false const v = {} == {}; '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool true variable: ::@topLevelVariable::v '''); @@ -625,7 +625,7 @@ bool true const v = {1, 2} == {1, 2}; '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool true variable: ::@topLevelVariable::v '''); @@ -636,7 +636,7 @@ bool true const v = const {} == const {}; '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool false variable: ::@topLevelVariable::v '''); @@ -647,7 +647,7 @@ bool false const v = 'foo' == Object(); '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool false variable: ::@topLevelVariable::v '''); @@ -665,7 +665,9 @@ const v = A() == 0; // [diag.constEvalPrimitiveEquality] In constant expressions, operands of the equality operator must have primitive equality. '''); var result = _topLevelVar(unitResult, 'v'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_equalEqual_userClass_hasHashCode() async { @@ -680,7 +682,9 @@ const v = A() == 0; // [diag.constEvalPrimitiveEquality] In constant expressions, operands of the equality operator must have primitive equality. '''); var result = _topLevelVar(unitResult, 'v'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_equalEqual_userClass_hasPrimitiveEquality_false() async { @@ -693,7 +697,7 @@ class A { const v = A(0) == 0; '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool false variable: ::@topLevelVariable::v '''); @@ -711,7 +715,9 @@ const v = A() == 0; // [diag.constEvalTypeBoolNumString] In constant expressions, operands of this operator must be of type 'bool', 'num', 'String' or 'null'. '''); var result = _topLevelVar(unitResult, 'v'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_equalEqual_userClass_hasPrimitiveEquality_true() async { @@ -724,7 +730,7 @@ class A { const v = A(0) == A(0); '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool true variable: ::@topLevelVariable::v '''); @@ -1138,7 +1144,7 @@ class C { const x = C(); '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' C constructorInvocation constructor: ConstructorMember @@ -1161,7 +1167,7 @@ class C { const x = C(E(42)); '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' C f: int 42 typeNotExtensionTypeErased: E @@ -1184,7 +1190,7 @@ extension type const E(int it) {} const x = E(42); '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' int 42 variable: ::@topLevelVariable::x typeNotExtensionTypeErased: E @@ -1199,7 +1205,7 @@ const a = E(42); const x = a is String; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool false variable: ::@topLevelVariable::x '''); @@ -1213,7 +1219,7 @@ const a = E(42); const x = a is int; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool true variable: ::@topLevelVariable::x '''); @@ -1226,7 +1232,7 @@ extension type const E(String it) {} const x = 42 is E; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool false variable: ::@topLevelVariable::x '''); @@ -1239,7 +1245,7 @@ extension type const E(int it) {} const x = 42 is E; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool true variable: ::@topLevelVariable::x '''); @@ -1252,7 +1258,7 @@ extension type const E(int it) {} const x = []; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' List variable: ::@topLevelVariable::x typeNotExtensionTypeErased: List @@ -1266,7 +1272,7 @@ extension type const E(int it) {} const x = [E(0), E(1)]; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' List elements int 0 @@ -1285,7 +1291,7 @@ extension type const E(int it) {} const x = {E(0): E(1)}; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Map entries entry @@ -1325,7 +1331,7 @@ class C { const c = C(x: 123, y: 456); '''); var result = _topLevelVar(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' C _x: int 123 _y: int 456 @@ -1344,7 +1350,7 @@ const dynamic d = 'foo'; const int? c = d?.length; '''); var result = _topLevelVar(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' int 3 variable: ::@topLevelVariable::c '''); @@ -1356,7 +1362,7 @@ const dynamic d = null; const int? c = d?.length; '''); var result = _topLevelVar(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Null null variable: ::@topLevelVariable::c '''); @@ -1368,7 +1374,7 @@ const List? l = null; const int? c = l?.length; '''); var result = _topLevelVar(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Null null variable: ::@topLevelVariable::c '''); @@ -1380,7 +1386,7 @@ const String? s = 'foo'; const int? c = s?.length; '''); var result = _topLevelVar(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' int 3 variable: ::@topLevelVariable::c '''); @@ -1392,7 +1398,7 @@ const String? s = null; const int? c = s?.length; '''); var result = _topLevelVar(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Null null variable: ::@topLevelVariable::c '''); @@ -1423,7 +1429,9 @@ class A { } '''); var result = _localVar(unitResult, 'x'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitBinaryExpression_extensionMethod() async { @@ -1438,7 +1446,9 @@ const v2 = v1 + v1; // [diag.constEvalExtensionMethod] Extension methods can't be used in constant expressions. '''); var result = _topLevelVar(unitResult, 'v2'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitBinaryExpression_extensionType() async { @@ -1453,7 +1463,9 @@ const v2 = v1 + 2; // [diag.constEvalExtensionTypeMethod] Extension type methods can't be used in constant expressions. '''); var result = _topLevelVar(unitResult, 'v2'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitBinaryExpression_extensionType_implementsInt() async { @@ -1533,7 +1545,9 @@ const c = 0xFFFFFFFF >>> -2; // [diag.constEvalThrowsException] Evaluation of this constant expression throws an exception. '''); var result = _topLevelVar(unitResult, 'c'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitBinaryExpression_gtGtGt_negative_zeroBits() async { @@ -1589,7 +1603,9 @@ const c = 0xFF >>> -2; // [diag.constEvalThrowsException] Evaluation of this constant expression throws an exception. '''); var result = _topLevelVar(unitResult, 'c'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitBinaryExpression_gtGtGt_positive_zeroBits() async { @@ -1670,7 +1686,7 @@ const bool b = false; const void Function(int p) h = b ? g : g; '''); var result = _topLevelVar(unitResult, 'h'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' void Function(int, {int? q}) element: ::@function::f typeArguments @@ -1706,7 +1722,9 @@ class A { } '''); var result = _topLevelVar(unitResult, 'x'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitConditionalExpression_unknownCondition_undefinedIdentifier() async { @@ -1720,7 +1738,9 @@ const x = kIsWeb ? a : b; // [diag.undefinedIdentifier] Undefined name 'b'. '''); var result = _topLevelVar(unitResult, 'x'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitConstructorDeclaration_cycle() async { @@ -2210,7 +2230,9 @@ const g = foo; // [diag.missingIdentifier] Expected an identifier. '''); var result = _topLevelVar(unitResult, 'g'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitFunctionReference_explicitTypeArgs_functionName_tooFew() async { @@ -2221,7 +2243,9 @@ const g = foo; // [diag.wrongNumberOfTypeArgumentsElement] The function 'foo' is declared with 2 type parameters, but 1 type arguments are given. '''); var result = _topLevelVar(unitResult, 'g'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitFunctionReference_explicitTypeArgs_functionName_tooMany() async { @@ -2232,7 +2256,9 @@ const g = foo; // [diag.wrongNumberOfTypeArgumentsElement] The function 'foo' is declared with 1 type parameters, but 2 type arguments are given. '''); var result = _topLevelVar(unitResult, 'g'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitFunctionReference_explicitTypeArgs_functionName_typeParameter() async { @@ -2828,7 +2854,9 @@ const x = [for (int i = 0; i < 3; i++) i]; // [diag.constEvalForElement] Constant expressions don't support 'for' elements. '''); var result = _topLevelVar(unitResult, 'x'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitListLiteral_ifElement_nonBoolCondition() async { @@ -2839,7 +2867,9 @@ const x = [1, if (c) 2 else 3, 4]; // [diag.nonBoolCondition] Conditions must have a static type of 'bool'. '''); var result = _topLevelVar(unitResult, 'x'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitListLiteral_ifElement_nonBoolCondition_static() async { @@ -2849,7 +2879,9 @@ const x = [1, if (1) 2 else 3, 4]; // [diag.nonBoolCondition] Conditions must have a static type of 'bool'. '''); var result = _topLevelVar(unitResult, 'x'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitListLiteral_listElement_explicitType() async { @@ -2942,7 +2974,9 @@ const x = [...a]; // [diag.constSpreadExpectedListOrSet] A list or a set is expected in this spread. '''); var result = _topLevelVar(unitResult, 'x'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitListLiteral_spreadElement_null() async { @@ -2954,7 +2988,7 @@ const List x = [ ]; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' List elements String anotherString @@ -2971,7 +3005,7 @@ const List x = [ ]; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' List elements String anotherString @@ -3018,7 +3052,7 @@ void f(int a) {} const g = self.f; '''); var result = _topLevelVar(unitResult, 'g'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' void Function(int) element: ::@function::f variable: ::@topLevelVariable::g @@ -3032,7 +3066,7 @@ void f(T a) {} const void Function(int) g = self.f; '''); var result = _topLevelVar(unitResult, 'g'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' void Function(int) element: ::@function::f typeArguments @@ -3050,7 +3084,7 @@ const g2 = f; const void Function(int) h = b ? g1 : g2; '''); var result = _topLevelVar(unitResult, 'h'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' void Function(int) element: ::@function::f typeArguments @@ -3067,7 +3101,7 @@ const g = f; const void Function(int) h = self.g; '''); var result = _topLevelVar(unitResult, 'h'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' void Function(int) element: ::@function::f typeArguments @@ -3084,7 +3118,7 @@ const g = f; const h = self.g; '''); var result = _topLevelVar(unitResult, 'h'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' void Function(T) element: ::@function::f variable: ::@topLevelVariable::h @@ -3112,7 +3146,7 @@ class RequiresNonEmptyList { const c = ~42; '''); var result = _topLevelVar(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' int -43 variable: ::@topLevelVariable::c '''); @@ -3130,7 +3164,9 @@ const v2 = -v1; // [diag.constEvalExtensionMethod] Extension methods can't be used in constant expressions. '''); var result = _topLevelVar(unitResult, 'v2'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitPrefixExpression_extensionType() async { @@ -3145,7 +3181,9 @@ const v2 = -v1; // [diag.constEvalExtensionTypeMethod] Extension type methods can't be used in constant expressions. '''); var result = _topLevelVar(unitResult, 'v2'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitPrefixExpression_extensionType_implementsInt() async { @@ -3236,7 +3274,7 @@ class C { const g = self.C.f; '''); var result = _topLevelVar(unitResult, 'g'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' void Function(int) element: ::@class::C::@method::f variable: ::@topLevelVariable::g @@ -3252,7 +3290,7 @@ class C { const void Function(int) g = self.C.f; '''); var result = _topLevelVar(unitResult, 'g'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' void Function(int) element: ::@class::C::@method::f typeArguments @@ -3270,7 +3308,7 @@ extension E on int { const g = self.E.f; '''); var result = _topLevelVar(unitResult, 'g'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' int Function(String) element: ::@extension::E::@method::f variable: ::@topLevelVariable::g @@ -3286,7 +3324,7 @@ extension type ET(int it) { const g = self.ET.f; '''); var result = _topLevelVar(unitResult, 'g'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' int Function(String) element: ::@extensionType::ET::@method::f variable: ::@topLevelVariable::g @@ -3482,7 +3520,9 @@ const x = {1: null, for (final i in const []) i: null}; // [diag.constEvalForElement] Constant expressions don't support 'for' elements. '''); var result = _topLevelVar(unitResult, 'x'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitSetOrMapLiteral_map_forElement_nested() async { @@ -3494,7 +3534,9 @@ const x = {1: null, if (true) for (final i in const []) i: null}; // [diag.constEvalForElement] Constant expressions don't support 'for' elements. '''); var result = _topLevelVar(unitResult, 'x'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitSetOrMapLiteral_map_ifElement_nonBoolCondition() async { @@ -3505,7 +3547,9 @@ const c = const {if (nonBool) 'a' : 1}; // [diag.nonBoolCondition] Conditions must have a static type of 'bool'. '''); var result = _topLevelVar(unitResult, 'c'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitSetOrMapLiteral_map_mapElement() async { @@ -3513,7 +3557,7 @@ const c = const {if (nonBool) 'a' : 1}; const x = {'a' : 'm', 'b' : 'n', 'c' : 'o'}; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Map entries entry @@ -3538,7 +3582,7 @@ const Map alwaysInclude = { }; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Map entries entry @@ -3570,7 +3614,7 @@ const Map x = { }; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Map entries entry @@ -3593,7 +3637,7 @@ const cm0 = C(-0.0); const a = {cp0, cm0}; '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Set elements C @@ -3624,7 +3668,9 @@ const x = {for (final i in set) i}; // [diag.constEvalForElement] Constant expressions don't support 'for' elements. '''); var result = _topLevelVar(unitResult, 'x'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitSetOrMapLiteral_set_ifElement_nonBoolCondition() async { @@ -3635,7 +3681,9 @@ const c = const {if (nonBool) 3}; // [diag.nonBoolCondition] Conditions must have a static type of 'bool'. '''); var result = _topLevelVar(unitResult, 'c'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitSetOrMapLiteral_set_spread_list() async { @@ -3647,7 +3695,7 @@ const Set x = { }; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Set elements String anotherString @@ -3665,7 +3713,7 @@ const Set x = { }; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Set elements String anotherString @@ -3679,7 +3727,7 @@ const a = C; class C {} '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Type toTypeValue: C toTypeValueNotExtensionTypeErased: C @@ -3693,7 +3741,7 @@ const a = E; extension type E(int it); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Type toTypeValue: int toTypeValueNotExtensionTypeErased: E @@ -3707,7 +3755,7 @@ const a = E(0); extension type const E(int it); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' int 0 variable: ::@topLevelVariable::a typeNotExtensionTypeErased: E @@ -3720,7 +3768,7 @@ void f(int a) {} const g = f; '''); var result = _topLevelVar(unitResult, 'g'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' void Function(int) element: ::@function::f variable: ::@topLevelVariable::g @@ -3733,7 +3781,7 @@ void f(T a) {} const void Function(int) g = f; '''); var result = _topLevelVar(unitResult, 'g'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' void Function(int) element: ::@function::f typeArguments @@ -3748,7 +3796,7 @@ void f(int a) {} const void Function(int) g = f; '''); var result = _topLevelVar(unitResult, 'g'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' void Function(int) element: ::@function::f variable: ::@topLevelVariable::g @@ -3762,7 +3810,7 @@ const g = f; const void Function(int) h = g; '''); var result = _topLevelVar(unitResult, 'h'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' void Function(int) element: ::@function::f typeArguments @@ -3778,7 +3826,7 @@ const g = f; const h = g; '''); var result = _topLevelVar(unitResult, 'h'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' void Function(T) element: ::@function::f variable: ::@topLevelVariable::h @@ -3795,7 +3843,7 @@ class C { } '''); var result = _field(unitResult, 'h'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' void Function(int, {int? b}) element: ::@function::f typeArguments @@ -3816,7 +3864,7 @@ class C { const c = C(f); '''); var result = _topLevelVar(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' C h: void Function(int, {int? b}) element: ::@function::f @@ -3840,7 +3888,7 @@ const void Function(T a) g = f; const void Function(int a) h = g; '''); var result = _topLevelVar(unitResult, 'h'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' void Function(int, {int? b}) element: ::@function::f typeArguments @@ -3861,7 +3909,9 @@ const v2 = -v1; // [diag.constEvalExtensionTypeMethod] Extension type methods can't be used in constant expressions. '''); var result = _topLevelVar(unitResult, 'v2'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } void _assertHasPrimitiveEqualityFalse( @@ -3892,7 +3942,7 @@ mixin ConstantVisitorTestCases on ConstantVisitorTestSupport { const c = [1, if (1 < 0) 2 else 3, 4]; '''); var result = _evaluateConstant(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' List elements int 1 @@ -3906,7 +3956,7 @@ List const c = [1, if (1 < 0) 2, 3]; '''); var result = _evaluateConstant(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' List elements int 1 @@ -3919,7 +3969,7 @@ List const c = [1, if (1 > 0) 2 else 3, 4]; '''); var result = _evaluateConstant(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' List elements int 1 @@ -3933,7 +3983,7 @@ List const c = [1, if (1 > 0) 2, 3]; '''); var result = _evaluateConstant(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' List elements int 1 @@ -3947,7 +3997,7 @@ List const c = [1, if (1 > 0) if (2 > 1) 2, 3]; '''); var result = _evaluateConstant(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' List elements int 1 @@ -3961,7 +4011,7 @@ List const c = [1, ...[2, 3], 4]; '''); var result = _evaluateConstant(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' List elements int 1 @@ -3976,7 +4026,7 @@ List const c = {'a' : 1, if (1 < 0) 'b' : 2 else 'c' : 3, 'd' : 4}; '''); var result = _evaluateConstant(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Map entries entry @@ -3996,7 +4046,7 @@ Map const c = {'a' : 1, if (1 < 0) 'b' : 2, 'c' : 3}; '''); var result = _evaluateConstant(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Map entries entry @@ -4013,7 +4063,7 @@ Map const c = {'a' : 1, if (1 > 0) 'b' : 2 else 'c' : 3, 'd' : 4}; '''); var result = _evaluateConstant(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Map entries entry @@ -4033,7 +4083,7 @@ Map const c = {'a' : 1, if (1 > 0) 'b' : 2, 'c' : 3}; '''); var result = _evaluateConstant(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Map entries entry @@ -4053,7 +4103,7 @@ Map const c = {'a' : 1, if (1 > 0) if (2 > 1) ...{'b' : 2}, 'c' : 3}; '''); var result = _evaluateConstant(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Map entries entry @@ -4073,7 +4123,7 @@ Map const c = {'a' : 1, ...{'b' : 2, 'c' : 3}, 'd' : 4}; '''); var result = _evaluateConstant(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Map entries entry @@ -4096,7 +4146,7 @@ Map const c = {1, if (1 < 0) 2 else 3, 4}; '''); var result = _evaluateConstant(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Set elements int 1 @@ -4110,7 +4160,7 @@ Set const c = {1, if (1 < 0) 2, 3}; '''); var result = _evaluateConstant(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Set elements int 1 @@ -4123,7 +4173,7 @@ Set const c = {1, if (1 > 0) 2 else 3, 4}; '''); var result = _evaluateConstant(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Set elements int 1 @@ -4137,7 +4187,7 @@ Set const c = {1, if (1 > 0) 2, 3}; '''); var result = _evaluateConstant(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Set elements int 1 @@ -4151,7 +4201,7 @@ Set const c = {1, if (1 > 0) if (2 > 1) 2, 3}; '''); var result = _evaluateConstant(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Set elements int 1 @@ -4165,7 +4215,7 @@ Set const c = {1, ...{2, 3}, 4}; '''); var result = _evaluateConstant(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Set elements int 1 @@ -4180,7 +4230,7 @@ Set const c = 'abc' 'def'; '''); var result = _topLevelVar(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' String abcdef variable: ::@topLevelVariable::c '''); @@ -4196,8 +4246,22 @@ class A { const A(); } '''); - DartObjectImpl resultA = _evaluateConstant(result, 'a'); - DartObjectImpl resultB = _evaluateConstant(result, 'b'); + + var resultA = _evaluateConstant(result, 'a'); + assertDartObjectText(resultA, r''' +A + constructorInvocation + constructor: ::@class::A::@constructor::new +'''); + + var resultB = _evaluateConstant(result, 'b'); + assertDartObjectText(resultB, r''' +A + constructorInvocation + constructor: ::@class::A::@constructor::new + variable: ::@topLevelVariable::a +'''); + expect(resultB, resultA); } @@ -4212,8 +4276,28 @@ class B extends A { const B(); } '''); - DartObjectImpl resultA = _evaluateConstant(result, 'a'); - DartObjectImpl resultB = _evaluateConstant(result, 'b'); + + var resultA = _evaluateConstant(result, 'a'); + assertDartObjectText(resultA, r''' +B + (super): A + constructorInvocation + constructor: ::@class::A::@constructor::new + constructorInvocation + constructor: ::@class::B::@constructor::new +'''); + + var resultB = _evaluateConstant(result, 'b'); + assertDartObjectText(resultB, r''' +B + (super): A + constructorInvocation + constructor: ::@class::A::@constructor::new + constructorInvocation + constructor: ::@class::B::@constructor::new + variable: ::@topLevelVariable::a +'''); + expect(resultB, resultA); } @@ -4231,7 +4315,9 @@ class B extends A { } '''); var result = _topLevelVar(unitResult, 'b'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitAsExpression_instanceOfUnrelatedClass() async { @@ -4248,7 +4334,9 @@ class B { } '''); var result = _topLevelVar(unitResult, 'b'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitAsExpression_potentialConst() async { @@ -4356,8 +4444,10 @@ const c = a && true; var unitResult = await resolveTestCodeWithDiagnostics(''' const c = false & true; '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'c'); - expect(result.type, unitResult.typeProvider.boolType); + var result = _evaluateConstant(unitResult, 'c'); + assertDartObjectText(result, r''' +bool false +'''); } test_visitBinaryExpression_and_bool_known_unknown() async { @@ -4365,8 +4455,10 @@ const c = false & true; const b = bool.fromEnvironment('y'); const c = false & b; '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'c'); - expect(result.type, unitResult.typeProvider.boolType); + var result = _evaluateConstant(unitResult, 'c'); + assertDartObjectText(result, r''' +bool false +'''); } test_visitBinaryExpression_and_bool_true_invalid() async { @@ -4383,8 +4475,10 @@ const c = true && a; const a = bool.fromEnvironment('x'); const c = a & true; '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'c'); - expect(result.type, unitResult.typeProvider.boolType); + var result = _evaluateConstant(unitResult, 'c'); + assertDartObjectText(result, r''' +bool false +'''); } test_visitBinaryExpression_and_bool_unknown_unknown() async { @@ -4393,8 +4487,10 @@ const a = bool.fromEnvironment('x'); const b = bool.fromEnvironment('y'); const c = a & b; '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'c'); - expect(result.type, unitResult.typeProvider.boolType); + var result = _evaluateConstant(unitResult, 'c'); + assertDartObjectText(result, r''' +bool false +'''); } test_visitBinaryExpression_and_int() async { @@ -4596,8 +4692,10 @@ const c = a || true; var unitResult = await resolveTestCodeWithDiagnostics(''' const c = false | true; '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'c'); - expect(result.type, unitResult.typeProvider.boolType); + var result = _evaluateConstant(unitResult, 'c'); + assertDartObjectText(result, r''' +bool true +'''); } test_visitBinaryExpression_or_bool_known_unknown() async { @@ -4605,8 +4703,10 @@ const c = false | true; const b = bool.fromEnvironment('y'); const c = false | b; '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'c'); - expect(result.type, unitResult.typeProvider.boolType); + var result = _evaluateConstant(unitResult, 'c'); + assertDartObjectText(result, r''' +bool false +'''); } test_visitBinaryExpression_or_bool_true_invalid() async { @@ -4625,8 +4725,10 @@ const c = true || a; const a = bool.fromEnvironment('x'); const c = a | true; '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'c'); - expect(result.type, unitResult.typeProvider.boolType); + var result = _evaluateConstant(unitResult, 'c'); + assertDartObjectText(result, r''' +bool true +'''); } test_visitBinaryExpression_or_bool_unknown_unknown() async { @@ -4635,16 +4737,20 @@ const a = bool.fromEnvironment('x'); const b = bool.fromEnvironment('y'); const c = a | b; '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'c'); - expect(result.type, unitResult.typeProvider.boolType); + var result = _evaluateConstant(unitResult, 'c'); + assertDartObjectText(result, r''' +bool false +'''); } test_visitBinaryExpression_or_int() async { var unitResult = await resolveTestCodeWithDiagnostics(''' const c = 3 | 5; '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'c'); - expect(result.type, unitResult.typeProvider.intType); + var result = _evaluateConstant(unitResult, 'c'); + assertDartObjectText(result, r''' +int 7 +'''); } test_visitBinaryExpression_or_known_known() async { @@ -4678,9 +4784,10 @@ const c = 'a' ?? 'b'; // ^^^ // [diag.deadNullAwareExpression] The left operand can't be null, so the right operand is never executed. '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'c'); - expect(result.type, unitResult.typeProvider.stringType); - expect(result.toStringValue(), 'a'); + var result = _evaluateConstant(unitResult, 'c'); + assertDartObjectText(result, r''' +String a +'''); } test_visitBinaryExpression_questionQuestion_null_invalid() async { @@ -4696,25 +4803,30 @@ class C {} var unitResult = await resolveTestCodeWithDiagnostics(''' const c = null ?? 'b'; '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'c'); - expect(result.type, unitResult.typeProvider.stringType); - expect(result.toStringValue(), 'b'); + var result = _evaluateConstant(unitResult, 'c'); + assertDartObjectText(result, r''' +String b +'''); } test_visitBinaryExpression_questionQuestion_null_null() async { var unitResult = await resolveTestCodeWithDiagnostics(''' const c = null ?? null; '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'c'); - expect(result.isNull, isTrue); + var result = _evaluateConstant(unitResult, 'c'); + assertDartObjectText(result, r''' +Null null +'''); } test_visitBinaryExpression_xor_bool_known_known() async { var unitResult = await resolveTestCodeWithDiagnostics(''' const c = false ^ true; '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'c'); - expect(result.type, unitResult.typeProvider.boolType); + var result = _evaluateConstant(unitResult, 'c'); + assertDartObjectText(result, r''' +bool true +'''); } test_visitBinaryExpression_xor_bool_known_unknown() async { @@ -4722,8 +4834,10 @@ const c = false ^ true; const b = bool.fromEnvironment('y'); const c = false ^ b; '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'c'); - expect(result.type, unitResult.typeProvider.boolType); + var result = _evaluateConstant(unitResult, 'c'); + assertDartObjectText(result, r''' +bool false +'''); } test_visitBinaryExpression_xor_bool_unknown_known() async { @@ -4731,8 +4845,10 @@ const c = false ^ b; const a = bool.fromEnvironment('x'); const c = a ^ true; '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'c'); - expect(result.type, unitResult.typeProvider.boolType); + var result = _evaluateConstant(unitResult, 'c'); + assertDartObjectText(result, r''' +bool true +'''); } test_visitBinaryExpression_xor_bool_unknown_unknown() async { @@ -4741,16 +4857,20 @@ const a = bool.fromEnvironment('x'); const b = bool.fromEnvironment('y'); const c = a ^ b; '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'c'); - expect(result.type, unitResult.typeProvider.boolType); + var result = _evaluateConstant(unitResult, 'c'); + assertDartObjectText(result, r''' +bool false +'''); } test_visitBinaryExpression_xor_int() async { var unitResult = await resolveTestCodeWithDiagnostics(''' const c = 3 ^ 5; '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'c'); - expect(result.type, unitResult.typeProvider.intType); + var result = _evaluateConstant(unitResult, 'c'); + assertDartObjectText(result, r''' +int 6 +'''); } test_visitBinaryExpression_xor_mixed() async { @@ -4945,9 +5065,10 @@ double 3.45 var unitResult = await resolveTestCodeWithDiagnostics(''' const double d = 3; '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'd'); - expect(result.type, unitResult.typeProvider.doubleType); - expect(result.toDoubleValue(), 3.0); + var result = _evaluateConstant(unitResult, 'd'); + assertDartObjectText(result, r''' +double 3.0 +'''); } test_visitIntegerLiteral_integer() async { @@ -5091,7 +5212,7 @@ bool true const c = null; '''); var result = _topLevelVar(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Null null variable: ::@topLevelVariable::c '''); @@ -5122,7 +5243,7 @@ const x = prefix.E.v; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' int 42 variable: ::@topLevelVariable::x '''); @@ -5159,7 +5280,9 @@ const v2 = v1.length; // [diag.constEvalExtensionTypeMethod] Extension type methods can't be used in constant expressions. '''); var result = _topLevelVar(unitResult, 'v2'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_visitPropertyAccess_length_extensionType_implementsString() async { @@ -5198,9 +5321,12 @@ const y = B(x); var unitResult = await resolveTestCodeWithDiagnostics(''' const a = dynamic; '''); - DartObjectImpl result = _evaluateConstant(unitResult, 'a'); - expect(result.type, unitResult.typeProvider.typeType); - expect(result.toTypeValue(), unitResult.typeProvider.dynamicType); + var result = _evaluateConstant(unitResult, 'a'); + assertDartObjectText(result, r''' +Type + toTypeValue: dynamic + toTypeValueNotExtensionTypeErased: dynamic +'''); } test_visitSimpleIdentifier_variable() async { @@ -5209,7 +5335,7 @@ const a = 42; const b = a; '''); var result = _topLevelVar(unitResult, 'b'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' int 42 variable: ::@topLevelVariable::b '''); @@ -5252,7 +5378,7 @@ int 3 const c = 'abc'; '''); var result = _topLevelVar(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' String abc variable: ::@topLevelVariable::c '''); @@ -5281,10 +5407,6 @@ String a3c } class ConstantVisitorTestSupport extends PubPackageResolutionTest { - void _assertNull(DartObjectImpl? result) { - expect(result, isNull); - } - DartObjectImpl _evaluateConstant( TestResolvedUnitResult unitResult, String name, { @@ -5412,7 +5534,7 @@ class A { const a = const A(); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' A constructorInvocation constructor: ::@class::A::@constructor::new @@ -5435,7 +5557,7 @@ const a = A(x: 0); // [diag.constEvalThrowsException][context 1] Evaluation of this constant expression throws an exception. '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' '''); } @@ -5454,7 +5576,7 @@ class A { const a = A(x: 1, y: 2); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' A _x: int 1 _y: int 2 @@ -5478,7 +5600,7 @@ class A { const a = A(x: 1); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' A _x: int 1 constructorInvocation @@ -5512,7 +5634,7 @@ class A { const c = const A(E.b); '''); var result = _topLevelVar(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' A constructorInvocation constructor: ::@class::A::@constructor::new @@ -5558,7 +5680,7 @@ class A { const a = const A(0); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' A constructorInvocation constructor: ::@class::A::@constructor::new @@ -5589,7 +5711,7 @@ class A { const v = const A(0); '''); var result = _topLevelVar(unitResult, 'v'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' A constructorInvocation constructor: ::@class::A::@constructor::new @@ -5622,7 +5744,7 @@ class A { const a = const A(); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' A constructorInvocation constructor: ::@class::A::@constructor::new @@ -5661,7 +5783,7 @@ class B extends A { const b = const B(); '''); var result = _topLevelVar(unitResult, 'b'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' B (super): A constructorInvocation @@ -5724,7 +5846,7 @@ class A { const a = const A(1); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' A constructorInvocation constructor: ::@class::A::@constructor::new @@ -5739,13 +5861,13 @@ A const a = bool.fromEnvironment('a'); const b = bool.fromEnvironment('b', defaultValue: true); '''); - assertDartObjectText(_topLevelVar(result, 'a'), ''' + assertDartObjectText(_topLevelVar(result, 'a'), r''' bool false variable: ::@topLevelVariable::a '''); assertDartObjectText( _evaluateConstant(result, 'a', declaredVariables: {'a': 'true'}), - ''' + r''' bool true ''', ); @@ -5755,7 +5877,7 @@ bool true 'b', declaredVariables: {'b': 'bbb'}, ); - assertDartObjectText(bResult, ''' + assertDartObjectText(bResult, r''' bool true '''); } @@ -5766,7 +5888,7 @@ bool true const a = bool.fromEnvironment('dart.library.js_interop'); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool variable: ::@topLevelVariable::a '''); @@ -5778,7 +5900,7 @@ const a = bool.fromEnvironment('dart.library.js_interop'); const a = bool.fromEnvironment('dart.library.js_util'); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' bool variable: ::@topLevelVariable::a '''); @@ -5792,12 +5914,12 @@ const left = [3, 1, 2, 4] == b; const right = b == [3, 1, 2, 4]; '''); var leftResult = _topLevelVar(result, 'left'); - assertDartObjectText(leftResult, ''' + assertDartObjectText(leftResult, r''' bool variable: ::@topLevelVariable::left '''); var rightResult = _topLevelVar(result, 'right'); - assertDartObjectText(rightResult, ''' + assertDartObjectText(rightResult, r''' bool variable: ::@topLevelVariable::right '''); @@ -5811,12 +5933,12 @@ const left = [3, if (a) ...[1] else ...[1, 2], 4] == b; const right = b == [3, if (a) ...[1] else ...[1, 2], 4]; '''); var leftResult = _topLevelVar(result, 'left'); - assertDartObjectText(leftResult, ''' + assertDartObjectText(leftResult, r''' bool variable: ::@topLevelVariable::left '''); var rightResult = _topLevelVar(result, 'right'); - assertDartObjectText(rightResult, ''' + assertDartObjectText(rightResult, r''' bool variable: ::@topLevelVariable::right '''); @@ -5828,7 +5950,7 @@ const a = bool.fromEnvironment('dart.library.js_util'); const x = {3:'3', if (a) 1:'1' else 2:'2', 4:'4'}; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Map variable: ::@topLevelVariable::x '''); @@ -5842,12 +5964,12 @@ const left = {3:'3', 2:'2', 4:'4'} == b; const right = b == {3:'3', 2:'2', 4:'4'}; '''); var leftResult = _topLevelVar(result, 'left'); - assertDartObjectText(leftResult, ''' + assertDartObjectText(leftResult, r''' bool variable: ::@topLevelVariable::left '''); var rightResult = _topLevelVar(result, 'right'); - assertDartObjectText(rightResult, ''' + assertDartObjectText(rightResult, r''' bool variable: ::@topLevelVariable::right '''); @@ -5861,12 +5983,12 @@ const left = {3:'3', if (a) 1:'1' else 2:'2', 4:'4'} == b; const right = b == {3:'3', if (a) 1:'1' else 2:'2', 4:'4'}; '''); var leftResult = _topLevelVar(result, 'left'); - assertDartObjectText(leftResult, ''' + assertDartObjectText(leftResult, r''' bool variable: ::@topLevelVariable::left '''); var rightResult = _topLevelVar(result, 'right'); - assertDartObjectText(rightResult, ''' + assertDartObjectText(rightResult, r''' bool variable: ::@topLevelVariable::right '''); @@ -5892,7 +6014,7 @@ const a = bool.fromEnvironment('dart.library.js_util'); const x = {3, if (a) ...[1] else ...[1, 2], 4}; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' Set variable: ::@topLevelVariable::x '''); @@ -5906,12 +6028,12 @@ const left = {3, 1, 4} == b; const right = b == {3, 1, 4}; '''); var leftResult = _topLevelVar(result, 'left'); - assertDartObjectText(leftResult, ''' + assertDartObjectText(leftResult, r''' bool variable: ::@topLevelVariable::left '''); var rightResult = _topLevelVar(result, 'right'); - assertDartObjectText(rightResult, ''' + assertDartObjectText(rightResult, r''' bool variable: ::@topLevelVariable::right '''); @@ -5925,12 +6047,12 @@ const left = {3, if (a) ...[1] else ...[1, 2], 4} == b; const right = b == {3, if (a) ...[1] else ...[1, 2], 4}; '''); var leftResult = _topLevelVar(result, 'left'); - assertDartObjectText(leftResult, ''' + assertDartObjectText(leftResult, r''' bool variable: ::@topLevelVariable::left '''); var rightResult = _topLevelVar(result, 'right'); - assertDartObjectText(rightResult, ''' + assertDartObjectText(rightResult, r''' bool variable: ::@topLevelVariable::right '''); @@ -5956,7 +6078,7 @@ const a = bool.fromEnvironment('dart.library.js_util'); const x = [3, if (a) ...[1] else ...[1, 2], 4]; '''); var result = _topLevelVar(unitResult, 'x'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' List variable: ::@topLevelVariable::x '''); @@ -5980,13 +6102,13 @@ class A { var result = await resolveTestCodeWithDiagnostics(''' const a = bool.hasEnvironment('a'); '''); - assertDartObjectText(_topLevelVar(result, 'a'), ''' + assertDartObjectText(_topLevelVar(result, 'a'), r''' bool false variable: ::@topLevelVariable::a '''); assertDartObjectText( _evaluateConstant(result, 'a', declaredVariables: {'a': '42'}), - ''' + r''' bool true ''', ); @@ -6931,7 +7053,7 @@ class A { const A a = .new(); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' A constructorInvocation constructor: ::@class::A::@constructor::new @@ -6962,7 +7084,7 @@ class A { const A a = .new(.b); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' A constructorInvocation constructor: ::@class::A::@constructor::new @@ -7006,13 +7128,13 @@ B const bool a = .fromEnvironment('a'); const bool b = .fromEnvironment('b', defaultValue: true); '''); - assertDartObjectText(_topLevelVar(result, 'a'), ''' + assertDartObjectText(_topLevelVar(result, 'a'), r''' bool false variable: ::@topLevelVariable::a '''); assertDartObjectText( _evaluateConstant(result, 'a', declaredVariables: {'a': 'true'}), - ''' + r''' bool true ''', ); @@ -7022,7 +7144,7 @@ bool true 'b', declaredVariables: {'b': 'bbb'}, ); - assertDartObjectText(bResult, ''' + assertDartObjectText(bResult, r''' bool true '''); } @@ -7031,13 +7153,13 @@ bool true var result = await resolveTestCodeWithDiagnostics(''' const bool a = .hasEnvironment('a'); '''); - assertDartObjectText(_topLevelVar(result, 'a'), ''' + assertDartObjectText(_topLevelVar(result, 'a'), r''' bool false variable: ::@topLevelVariable::a '''); assertDartObjectText( _evaluateConstant(result, 'a', declaredVariables: {'a': '42'}), - ''' + r''' bool true ''', ); @@ -7053,7 +7175,7 @@ extension type const B(A a) {} const B b = .new(A()); '''); var result = _topLevelVar(unitResult, 'b'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' A constructorInvocation constructor: ::@class::A::@constructor::new @@ -7075,7 +7197,7 @@ const C c = .new(); '''); var result = _topLevelVar(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' C one: int 1 constructorInvocation @@ -7097,7 +7219,7 @@ const C c = .new(1); '''); var result = _topLevelVar(unitResult, 'c'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' C one: int 1 constructorInvocation @@ -7360,7 +7482,7 @@ class A { const a = const A(); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' A f: void Function(int) element: ::@function::g @@ -7383,7 +7505,7 @@ class A { const a = const A(); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' A f: Type toTypeValue: int @@ -7405,7 +7527,7 @@ class A { const a = const A(); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' A f: Type toTypeValue: dynamic @@ -7428,7 +7550,7 @@ typedef B = A; const a = const B(); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' A f: Type toTypeValue: int @@ -7459,7 +7581,9 @@ const a = const A(); // [diag.constTypeParameter][context 1] Type parameters can't be used in a constant expression. '''); var result = _topLevelVar(unitResult, 'a'); - _assertNull(result); + assertDartObjectText(result, r''' + +'''); } test_fieldInitializer_visitAsExpression_potentialConstType() async { @@ -7483,13 +7607,13 @@ const a = int.fromEnvironment('a'); const b = int.fromEnvironment('b', defaultValue: 42); '''); - assertDartObjectText(_topLevelVar(result, 'a'), ''' + assertDartObjectText(_topLevelVar(result, 'a'), r''' int 0 variable: ::@topLevelVariable::a '''); assertDartObjectText( _evaluateConstant(result, 'a', declaredVariables: {'a': '5'}), - ''' + r''' int 5 ''', ); @@ -7499,7 +7623,7 @@ int 5 'b', declaredVariables: {'b': 'bbb'}, ); - assertDartObjectText(bResult, ''' + assertDartObjectText(bResult, r''' int 42 '''); } @@ -7577,7 +7701,7 @@ class A { const a = const A(); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' A f: Type toTypeValue: int @@ -7625,13 +7749,13 @@ C var result = await resolveTestCodeWithDiagnostics(''' const a = String.fromEnvironment('a'); '''); - assertDartObjectText(_topLevelVar(result, 'a'), ''' + assertDartObjectText(_topLevelVar(result, 'a'), r''' String variable: ::@topLevelVariable::a '''); assertDartObjectText( _evaluateConstant(result, 'a', declaredVariables: {'a': 'test'}), - ''' + r''' String test ''', ); @@ -8034,7 +8158,7 @@ class B extends A { const a = const B(); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' B (super): A f: Type @@ -8068,7 +8192,7 @@ class B extends A { const a = const B(); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' B (super): A f: Type @@ -8098,7 +8222,7 @@ class A { const a = const A(1); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' A _: int 1 constructorInvocation @@ -8135,7 +8259,7 @@ class B extends A { const a = const B(1); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' B (super): A _: int 1 @@ -8166,7 +8290,7 @@ class B extends A { const a = const B(10); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' B (super): A _: int 10 @@ -8198,7 +8322,7 @@ class B extends A { const a = const B(1, 2); '''); var result = _topLevelVar(unitResult, 'a'); - assertDartObjectText(result, ''' + assertDartObjectText(result, r''' B (super): A _: int 1 diff --git a/pkg/analyzer/test/src/dart/resolution/constant_test.dart b/pkg/analyzer/test/src/dart/resolution/constant_test.dart index 828bbc18615..d4592b45a40 100644 --- a/pkg/analyzer/test/src/dart/resolution/constant_test.dart +++ b/pkg/analyzer/test/src/dart/resolution/constant_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:analyzer/src/dart/constant/value.dart'; -import 'package:analyzer/src/dart/element/element.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; @@ -41,7 +39,9 @@ const a = const A(); // To evaluate `const A()` we have to evaluate `{int p}`. // Even if its value is `null`. expect(p.isConstantEvaluated, isTrue); - expect(p.computeConstantValue()!.isNull, isTrue); + assertDartObjectText(p.computeConstantValue(), r''' +Null null +'''); } test_constFactoryRedirection_super() async { @@ -66,7 +66,19 @@ main() {} var node = result.findNode.annotation('@I'); var value = node.elementAnnotation!.computeConstantValue()!; - expect(value.getField('(super)')!.getField('f')!.toIntValue(), 42); + assertDartObjectText(value, r''' +B + (super): A + f: int 42 + constructorInvocation + constructor: ::@class::A::@constructor::new + positionalArguments + 0: int 42 + constructorInvocation + constructor: ::@class::I::@constructor::new + positionalArguments + 0: int 42 +'''); } test_constList_withNullAwareElement() async { @@ -212,7 +224,10 @@ import 'a.dart'; var import_ = result.findElement.importFind('package:test/a.dart'); var a = import_.topVar('a'); - expect(a.computeConstantValue()!.toIntValue(), 42); + assertDartObjectText(a.computeConstantValue(), r''' +int 42 + variable: package:test/a.dart::@topLevelVariable::a +'''); } test_imported_prefixedIdentifier_staticField_extension() async { @@ -231,7 +246,10 @@ import 'a.dart'; var import_ = result.findElement.importFind('package:test/a.dart'); var a = import_.topVar('a'); - expect(a.computeConstantValue()!.toIntValue(), 42); + assertDartObjectText(a.computeConstantValue(), r''' +int 42 + variable: package:test/a.dart::@topLevelVariable::a +'''); } test_imported_prefixedIdentifier_staticField_mixin() async { @@ -252,7 +270,10 @@ import 'a.dart'; var import_ = result.findElement.importFind('package:test/a.dart'); var a = import_.topVar('a'); - expect(a.computeConstantValue()!.toIntValue(), 42); + assertDartObjectText(a.computeConstantValue(), r''' +int 42 + variable: package:test/a.dart::@topLevelVariable::a +'''); } test_imported_super_defaultFieldFormalParameter() async { @@ -281,10 +302,18 @@ class B extends A { }); var aResult = results[a]!; - var bElement = aResult.findElement.field('b') as FieldElementImpl; - var bValue = bElement.evaluationResult as DartObjectImpl; - var superFields = bValue.getField(GenericState.SUPERCLASS_FIELD); - expect(superFields!.getField('f1')!.toBoolValue(), false); + var bElement = aResult.findElement.field('b'); + assertDartObjectText(bElement.computeConstantValue(), r''' +B + (super): A + f1: bool false + f2: bool false + constructorInvocation + constructor: package:test/a.dart::@class::A::@constructor::new + constructorInvocation + constructor: ::@class::B::@constructor::new + variable: package:test/a.dart::@class::A::@field::b +'''); } test_local_prefixedIdentifier_staticField_extension() async { @@ -296,6 +325,9 @@ extension E on int { } '''); var a = result.findElement.topVar('a'); - expect(a.computeConstantValue()!.toIntValue(), 42); + assertDartObjectText(a.computeConstantValue(), r''' +int 42 + variable: ::@topLevelVariable::a +'''); } }