Skip to content

Commit 329760d

Browse files
jensjohaCommit Queue
authored andcommitted
[cfe/parser] Parser doesn't set wrong endToken on handleThrowExpression; fix cfe coverage related to that
Change-Id: Ie1f936d1b914f38a819b3761770742c60d9be1e4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392121 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Jens Johansen <[email protected]>
1 parent 6d4ebea commit 329760d

18 files changed

+184
-149
lines changed

pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8844,7 +8844,7 @@ class Parser {
88448844
token = allowCascades
88458845
? parseExpression(throwToken)
88468846
: parseExpressionWithoutCascade(throwToken);
8847-
listener.handleThrowExpression(throwToken, token.next!);
8847+
listener.handleThrowExpression(throwToken, token);
88488848
return token;
88498849
}
88508850

pkg/front_end/lib/src/base/incremental_compiler.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2774,7 +2774,6 @@ class _ComponentProblems {
27742774
// Report old problems that wasn't reported again.
27752775
for (MapEntry<Uri, List<DiagnosticMessageFromJson>> entry
27762776
in _remainingComponentProblems.entries) {
2777-
// Coverage-ignore-block(suite): Not run.
27782777
List<DiagnosticMessageFromJson> messages = entry.value;
27792778
for (int i = 0; i < messages.length; i++) {
27802779
DiagnosticMessageFromJson message = messages[i];

pkg/front_end/lib/src/base/modifiers.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,6 @@ extension type const Modifiers(int _mask) implements Object {
206206
Keyword.CONST => _constMask,
207207
Keyword.FINAL => _finalMask,
208208
Keyword.VAR => 0,
209-
// Coverage-ignore(suite): Not run.
210209
_ => // Coverage-ignore(suite): Not run.
211210
throw new UnsupportedError(
212211
"Unexpected varFinalOrConst token $varFinalOrConst."),

pkg/front_end/lib/src/base/processed_options.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,11 +962,12 @@ class ProcessedOptions {
962962
}
963963
}
964964

965-
// Coverage-ignore(suite): Not run.
966965
Future<String?> _readAsString(FileSystemEntity file) async {
967966
try {
968967
return await file.readAsString();
969-
} on FileSystemException catch (error) {
968+
}
969+
// Coverage-ignore(suite): Not run.
970+
on FileSystemException catch (error) {
970971
reportWithoutLocation(
971972
templateCantReadFile.withArguments(
972973
error.uri, osErrorMessage(error.message)),

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class DynamicInterfaceSpecification {
9090
void _verifyKeys(YamlMap map, Set<String> allowedKeys) {
9191
for (dynamic k in map.keys) {
9292
if (!allowedKeys.contains(k.toString())) {
93+
// Coverage-ignore-block(suite): Not run.
9394
throw 'Unexpected key "$k" in dynamic interface specification';
9495
}
9596
}
@@ -108,6 +109,7 @@ class DynamicInterfaceSpecification {
108109

109110
final String librarySpec = yamlMap['library'] as String;
110111
if (librarySpec.endsWith('*')) {
112+
// Coverage-ignore-block(suite): Not run.
111113
_verifyKeys(yamlMap, const {'library'});
112114
final String prefix = baseUri
113115
.resolve(librarySpec.substring(0, librarySpec.length - 1))
@@ -126,6 +128,7 @@ class DynamicInterfaceSpecification {
126128
if (yamlMap.containsKey('class')) {
127129
final dynamic yamlClassNode = yamlMap['class'];
128130
if (yamlClassNode is YamlList) {
131+
// Coverage-ignore-block(suite): Not run.
129132
_verifyKeys(yamlMap, const {'library', 'class'});
130133
for (dynamic c in yamlClassNode) {
131134
result.add(libraryIndex.getClass(libraryUri, c as String));
@@ -167,10 +170,12 @@ class DynamicInterfaceSpecification {
167170
void _validateSpecifiedMember(Member member,
168171
{required bool allowStaticMembers, required bool allowInstanceMembers}) {
169172
if (member.isInstanceMember) {
173+
// Coverage-ignore-block(suite): Not run.
170174
if (!allowInstanceMembers) {
171175
throw 'Expected non-instance member $member';
172176
}
173177
} else {
178+
// Coverage-ignore-block(suite): Not run.
174179
if (!allowStaticMembers) {
175180
throw 'Expected instance member $member';
176181
}
@@ -290,12 +295,14 @@ class _DynamicModuleValidator extends RecursiveVisitor {
290295
}
291296

292297
@override
298+
// Coverage-ignore(suite): Not run.
293299
void visitInstanceGetterInvocation(InstanceGetterInvocation node) {
294300
_verifyCallable(node.interfaceTarget, node);
295301
super.visitInstanceGetterInvocation(node);
296302
}
297303

298304
@override
305+
// Coverage-ignore(suite): Not run.
299306
void visitEqualsCall(EqualsCall node) {
300307
_verifyCallable(node.interfaceTarget, node);
301308
super.visitEqualsCall(node);
@@ -308,18 +315,21 @@ class _DynamicModuleValidator extends RecursiveVisitor {
308315
}
309316

310317
@override
318+
// Coverage-ignore(suite): Not run.
311319
void visitSuperPropertyGet(SuperPropertyGet node) {
312320
_verifyCallable(node.interfaceTarget, node);
313321
super.visitSuperPropertyGet(node);
314322
}
315323

316324
@override
325+
// Coverage-ignore(suite): Not run.
317326
void visitSuperPropertySet(SuperPropertySet node) {
318327
_verifyCallable(node.interfaceTarget, node);
319328
super.visitSuperPropertySet(node);
320329
}
321330

322331
@override
332+
// Coverage-ignore(suite): Not run.
323333
void visitSuperMethodInvocation(SuperMethodInvocation node) {
324334
_verifyCallable(node.interfaceTarget, node);
325335
super.visitSuperMethodInvocation(node);
@@ -362,6 +372,7 @@ class _DynamicModuleValidator extends RecursiveVisitor {
362372
}
363373

364374
@override
375+
// Coverage-ignore(suite): Not run.
365376
void visitRedirectingFactoryTearOff(RedirectingFactoryTearOff node) {
366377
_verifyCallable(node.target, node);
367378
super.visitRedirectingFactoryTearOff(node);
@@ -408,23 +419,28 @@ class _DynamicModuleValidator extends RecursiveVisitor {
408419
}
409420

410421
@override
422+
// Coverage-ignore(suite): Not run.
411423
void visitExtensionType(ExtensionType node) {
412424
node.extensionTypeErasure.accept(this);
413425
}
414426

415427
@override
428+
// Coverage-ignore(suite): Not run.
416429
void visitAbstractSuperPropertyGet(AbstractSuperPropertyGet node) =>
417430
throw 'Unexpected node ${node.runtimeType} $node';
418431

419432
@override
433+
// Coverage-ignore(suite): Not run.
420434
void visitAbstractSuperPropertySet(AbstractSuperPropertySet node) =>
421435
throw 'Unexpected node ${node.runtimeType} $node';
422436

423437
@override
438+
// Coverage-ignore(suite): Not run.
424439
void visitAbstractSuperMethodInvocation(AbstractSuperMethodInvocation node) =>
425440
throw 'Unexpected node ${node.runtimeType} $node';
426441

427442
@override
443+
// Coverage-ignore(suite): Not run.
428444
void visitInstanceCreation(InstanceCreation node) =>
429445
throw 'Unexpected node ${node.runtimeType} $node';
430446

@@ -448,20 +464,23 @@ class _DynamicModuleValidator extends RecursiveVisitor {
448464
}
449465

450466
@override
467+
// Coverage-ignore(suite): Not run.
451468
void visitConstructorTearOffConstantReference(
452469
ConstructorTearOffConstant node) {
453470
_verifyCallable(node.target, _enclosingTreeNode!);
454471
super.visitConstructorTearOffConstantReference(node);
455472
}
456473

457474
@override
475+
// Coverage-ignore(suite): Not run.
458476
void visitRedirectingFactoryTearOffConstantReference(
459477
RedirectingFactoryTearOffConstant node) {
460478
_verifyCallable(node.target, _enclosingTreeNode!);
461479
super.visitRedirectingFactoryTearOffConstantReference(node);
462480
}
463481

464482
@override
483+
// Coverage-ignore(suite): Not run.
465484
void visitTypedefTearOffConstantReference(TypedefTearOffConstant node) =>
466485
throw 'Unexpected node ${node.runtimeType} $node';
467486

@@ -505,6 +524,7 @@ class _DynamicModuleValidator extends RecursiveVisitor {
505524
node.fileOffset,
506525
noLength,
507526
node.location!.file);
527+
// Coverage-ignore(suite): Not run.
508528
case _:
509529
throw 'Unexpected node ${node.runtimeType} $node';
510530
}
@@ -543,6 +563,7 @@ class _DynamicModuleValidator extends RecursiveVisitor {
543563
if (comparison < 0) {
544564
++i;
545565
} else if (comparison > 0) {
566+
// Coverage-ignore-block(suite): Not run.
546567
++j;
547568
} else {
548569
if (!identical(impl, interfaceMember)) {
@@ -574,8 +595,10 @@ class _DynamicModuleValidator extends RecursiveVisitor {
574595
Library _enclosingLibrary(TreeNode node) => switch (node) {
575596
Member() => node.enclosingLibrary,
576597
Class() => node.enclosingLibrary,
598+
// Coverage-ignore(suite): Not run.
577599
Library() => node,
578-
_ => throw 'Unexpected node ${node.runtimeType} $node'
600+
_ => // Coverage-ignore(suite): Not run.
601+
throw 'Unexpected node ${node.runtimeType} $node'
579602
};
580603

581604
bool _isSpecified(TreeNode node, Set<TreeNode> specified) =>
@@ -586,6 +609,7 @@ class _DynamicModuleValidator extends RecursiveVisitor {
586609
Class() =>
587610
node.name[0] != '_' && _isSpecified(node.enclosingLibrary, specified),
588611
Library() => false,
589-
_ => throw 'Unexpected node ${node.runtimeType} $node'
612+
_ => // Coverage-ignore(suite): Not run.
613+
throw 'Unexpected node ${node.runtimeType} $node'
590614
};
591615
}

pkg/front_end/lib/src/kernel/macro/annotation_parser.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,14 @@ class _MacroListener implements Listener {
416416

417417
@override
418418
void handleLiteralDoubleWithSeparators(Token token) {
419-
push(new _MacroArgumentNode(new macro.DoubleArgument(
420-
doubleFromToken(token, hasSeparators: true))));
419+
push(new _MacroArgumentNode(
420+
new macro.DoubleArgument(doubleFromToken(token, hasSeparators: true))));
421421
}
422422

423423
@override
424424
void handleLiteralInt(Token token) {
425-
push(new _MacroArgumentNode(new macro.IntArgument(
426-
intFromToken(token, hasSeparators: false)!)));
425+
push(new _MacroArgumentNode(
426+
new macro.IntArgument(intFromToken(token, hasSeparators: false)!)));
427427
}
428428

429429
@override

pkg/front_end/lib/src/kernel/macro/metadata.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ bool _isDartLibrary(Uri importUri, Uri fileUri) {
3333
return importUri.isScheme("dart") || fileUri.isScheme("org-dartlang-sdk");
3434
}
3535

36+
// Coverage-ignore(suite): Not run.
3637
/// Creates a [shared.Expression] for the annotation at [atToken].
3738
///
3839
/// If [delayLookupForTesting] is `true`, identifiers are not looked up in their
@@ -41,7 +42,6 @@ bool _isDartLibrary(Uri importUri, Uri fileUri) {
4142
/// A subsequent call to [shared.Expression.resolve] will perform the lookup
4243
/// a create the resolved expression. This is used in testing to mimic the
4344
/// scenario in which the declaration is added to the scope via macros.
44-
// Coverage-ignore(suite): Not run.
4545
shared.Expression parseAnnotation(
4646
Loader loader, Token atToken, Uri importUri, Uri fileUri, LookupScope scope,
4747
{bool delayLookupForTesting = false}) {

pkg/front_end/lib/src/type_inference/type_constraint_gatherer.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,7 @@ class TypeConstraintGatherer extends shared.TypeConstraintGenerator<
522522
// Coverage-ignore(suite): Not run.
523523
(DartType type, ignored) => type is UnknownType
524524
? false
525-
:
526-
// Coverage-ignore(suite): Not run.
527-
throw new UnsupportedError(
525+
: throw new UnsupportedError(
528526
"Unsupported type '${type.runtimeType}'."));
529527
for (GeneratedTypeConstraint constraint in constraints) {
530528
if (constraint.isUpper) {

pkg/front_end/parser_testcases/error_recovery/keyword_named_class_methods.dart.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4223,7 +4223,7 @@ beginCompilationUnit(class)
42234223
beginBinaryExpression(+)
42244224
handleLiteralInt(1)
42254225
endBinaryExpression(+, 1)
4226-
handleThrowExpression(throw, ;)
4226+
handleThrowExpression(throw, 1)
42274227
endReturnStatement(true, return, ;)
42284228
endBlockFunctionBody(2, {, })
42294229
endClassMethod(null, int, (, null, })

pkg/front_end/parser_testcases/error_recovery/keyword_named_class_methods.dart.intertwined.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9336,7 +9336,7 @@ parseUnit(class)
93369336
parseLiteralInt(+)
93379337
listener: handleLiteralInt(1)
93389338
listener: endBinaryExpression(+, 1)
9339-
listener: handleThrowExpression(throw, ;)
9339+
listener: handleThrowExpression(throw, 1)
93409340
ensureSemicolon(1)
93419341
listener: endReturnStatement(true, return, ;)
93429342
inGenerator()

0 commit comments

Comments
 (0)