Skip to content

Commit 2455ace

Browse files
johnniwintherCommit Queue
authored andcommitted
Revert "[model] Update handling of ?.length in constants"
This reverts commit b5e1ef4. Reason for revert: Analyzer didn't report an error in all cases, so this is a breaking change. Original change's description: > [model] Update handling of ?.length in constants > > This adds reporting of an error in CFE for ?.length in constant expressions and improves the message for the analyzer in the same case. The error in the analyzer was previously the invalid claim that > > The property 'length' can't be accessed on the type 'Null' in a constant expression. > > Closes #60509 > > Change-Id: Ibbe0fa1ace3bea9d83efea2ccf3ea9716a125d74 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421841 > Reviewed-by: Konstantin Shcheglov <[email protected]> > Commit-Queue: Johnni Winther <[email protected]> > Reviewed-by: Brian Wilkerson <[email protected]> Change-Id: I1bbe77b7abed5603dc062a235463bb4e0e755f23 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426860 Bot-Commit: Rubber Stamper <[email protected]> Reviewed-by: Ivan Inozemtsev <[email protected]> Reviewed-by: Alexander Thomas <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent c11186b commit 2455ace

25 files changed

+0
-214
lines changed

pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,17 +2112,6 @@ const MessageCode messageConstEvalNotMapInSpread = const MessageCode(
21122112
problemMessage: r"""Only maps can be used in spreads in constant maps.""",
21132113
);
21142114

2115-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
2116-
const Code<Null> codeConstEvalNullAwareAccess = messageConstEvalNullAwareAccess;
2117-
2118-
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
2119-
const MessageCode messageConstEvalNullAwareAccess = const MessageCode(
2120-
"ConstEvalNullAwareAccess",
2121-
analyzerCodes: <String>["CONST_EVAL_NULL_AWARE_ACCESS"],
2122-
problemMessage:
2123-
r"""Null-aware property access can't be used in a constant expression.""",
2124-
);
2125-
21262115
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
21272116
const Code<Null> codeConstEvalNullValue = messageConstEvalNullValue;
21282117

pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,6 @@ CompileTimeErrorCode.CONST_EVAL_FOR_ELEMENT:
426426
status: needsEvaluation
427427
CompileTimeErrorCode.CONST_EVAL_METHOD_INVOCATION:
428428
status: needsEvaluation
429-
CompileTimeErrorCode.CONST_EVAL_NULL_AWARE_ACCESS:
430-
status: needsEvaluation
431429
CompileTimeErrorCode.CONST_EVAL_PRIMITIVE_EQUALITY:
432430
status: needsEvaluation
433431
CompileTimeErrorCode.CONST_EVAL_PROPERTY_ACCESS:

pkg/analyzer/lib/src/dart/constant/constant_verifier.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -705,10 +705,6 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
705705
diagnosticCode,
706706
CompileTimeErrorCode.CONST_EVAL_METHOD_INVOCATION,
707707
) ||
708-
identical(
709-
diagnosticCode,
710-
CompileTimeErrorCode.CONST_EVAL_NULL_AWARE_ACCESS,
711-
) ||
712708
identical(
713709
diagnosticCode,
714710
CompileTimeErrorCode.CONST_EVAL_PRIMITIVE_EQUALITY,

pkg/analyzer/lib/src/dart/constant/evaluation.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,13 +1289,6 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
12891289
return prefixResult;
12901290
}
12911291

1292-
if (node.isNullAware) {
1293-
return InvalidConstant.forEntity(
1294-
entity: node,
1295-
diagnosticCode: CompileTimeErrorCode.CONST_EVAL_NULL_AWARE_ACCESS,
1296-
);
1297-
}
1298-
12991292
var propertyAccessResult = _evaluatePropertyAccess(
13001293
prefixResult,
13011294
node.propertyName,

pkg/analyzer/lib/src/error/codes.g.dart

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,12 +1025,6 @@ class CompileTimeErrorCode extends DiagnosticCode {
10251025
"Methods can't be invoked in constant expressions.",
10261026
);
10271027

1028-
static const CompileTimeErrorCode CONST_EVAL_NULL_AWARE_ACCESS =
1029-
CompileTimeErrorCode(
1030-
'CONST_EVAL_NULL_AWARE_ACCESS',
1031-
"Null-aware property access can't be used in a constant expression.",
1032-
);
1033-
10341028
/// See https://spec.dart.dev/DartLangSpecDraft.pdf#constants, "Constants",
10351029
/// for text about "An expression of the form e1 == e2".
10361030
static const CompileTimeErrorCode CONST_EVAL_PRIMITIVE_EQUALITY =

pkg/analyzer/lib/src/error/error_code_values.g.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ const List<DiagnosticCode> errorCodeValues = [
136136
CompileTimeErrorCode.CONST_EVAL_EXTENSION_TYPE_METHOD,
137137
CompileTimeErrorCode.CONST_EVAL_FOR_ELEMENT,
138138
CompileTimeErrorCode.CONST_EVAL_METHOD_INVOCATION,
139-
CompileTimeErrorCode.CONST_EVAL_NULL_AWARE_ACCESS,
140139
CompileTimeErrorCode.CONST_EVAL_PRIMITIVE_EQUALITY,
141140
CompileTimeErrorCode.CONST_EVAL_PROPERTY_ACCESS,
142141
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,

pkg/analyzer/lib/src/lint/constants.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class _ConstantAnalysisErrorListener extends AnalysisErrorListener {
4949
case CompileTimeErrorCode.CONST_EVAL_EXTENSION_METHOD:
5050
case CompileTimeErrorCode.CONST_EVAL_EXTENSION_TYPE_METHOD:
5151
case CompileTimeErrorCode.CONST_EVAL_METHOD_INVOCATION:
52-
case CompileTimeErrorCode.CONST_EVAL_NULL_AWARE_ACCESS:
5352
case CompileTimeErrorCode.CONST_EVAL_PROPERTY_ACCESS:
5453
case CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL:
5554
case CompileTimeErrorCode.CONST_EVAL_TYPE_BOOL_INT:

pkg/analyzer/messages.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,9 +2824,6 @@ CompileTimeErrorCode:
28242824
problemMessage: "Constant expressions don't support 'for' elements."
28252825
correctionMessage: "Try replacing the 'for' element with a spread, or removing 'const'."
28262826
hasPublishedDocs: false
2827-
CONST_EVAL_NULL_AWARE_ACCESS:
2828-
problemMessage: "Null-aware property access can't be used in a constant expression."
2829-
hasPublishedDocs: false
28302827
CONST_EVAL_PROPERTY_ACCESS:
28312828
problemMessage: "The property '{0}' can't be accessed on the type '{1}' in a constant expression."
28322829
hasPublishedDocs: false

pkg/analyzer/test/src/diagnostics/const_eval_property_access_test.dart

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,4 @@ const x = const C().t;
9090
[error(CompileTimeErrorCode.CONST_EVAL_PROPERTY_ACCESS, 59, 11)],
9191
);
9292
}
93-
94-
test_null_aware_property_access() async {
95-
await assertErrorsInCode(
96-
r'''
97-
const String? s = null;
98-
const int? c = s?.length;''',
99-
[error(CompileTimeErrorCode.CONST_EVAL_NULL_AWARE_ACCESS, 39, 9)],
100-
);
101-
}
10293
}

pkg/front_end/lib/src/kernel/body_builder.dart

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,10 +2872,6 @@ class BodyBuilder extends StackListenerImpl
28722872
]));
28732873
Object? send = pop();
28742874
if (send is Selector) {
2875-
if (send is PropertySelector && constantContext != ConstantContext.none) {
2876-
addProblem(
2877-
cfe.messageConstEvalNullAwareAccess, token.charOffset, noLength);
2878-
}
28792875
push(send.withReceiver(pop(), token.charOffset, isNullAware: true));
28802876
} else {
28812877
pop();

0 commit comments

Comments
 (0)