Skip to content

Commit f8b306c

Browse files
johnniwintherCommit Bot
authored and
Commit Bot
committed
[cfe] Don't check bounds on uninferred invocations
Invocations that haven't been inferred are now not checked wrt. bounds. These can occur in erroneous code or in outline expressions that are currently created both in the outline phase (where they are fully inferred) and in the body building phase where they are not inferred. Additionally, an assertion is added to verify that these invocations are no longer part of the AST, and therefore safe to leave incomplete. Closes #48148 Change-Id: I6d83c2db05d43b016e21abf915cbe5a312b20c79 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/228560 Reviewed-by: Chloe Stefantsova <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent 24ee012 commit f8b306c

11 files changed

+789
-64
lines changed

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,11 @@ class BodyBuilder extends ScopeListener<JumpTarget>
13871387
void _unaliasTypeAliasedConstructorInvocations() {
13881388
for (TypeAliasedConstructorInvocation invocation
13891389
in typeAliasedConstructorInvocations) {
1390+
if (!invocation.hasBeenInferred) {
1391+
assert(
1392+
isOrphaned(invocation), "Node $invocation has not been inferred.");
1393+
continue;
1394+
}
13901395
bool inferred = !hasExplicitTypeArguments(invocation.arguments);
13911396
DartType aliasedType = new TypedefType(
13921397
invocation.typeAliasBuilder.typedef,
@@ -1416,6 +1421,11 @@ class BodyBuilder extends ScopeListener<JumpTarget>
14161421
typeAliasedFactoryInvocations.toList();
14171422
typeAliasedFactoryInvocations.clear();
14181423
for (TypeAliasedFactoryInvocation invocation in invocations) {
1424+
if (!invocation.hasBeenInferred) {
1425+
assert(
1426+
isOrphaned(invocation), "Node $invocation has not been inferred.");
1427+
continue;
1428+
}
14191429
bool inferred = !hasExplicitTypeArguments(invocation.arguments);
14201430
DartType aliasedType = new TypedefType(
14211431
invocation.typeAliasBuilder.typedef,
@@ -7738,3 +7748,43 @@ class _BodyBuilderCloner extends CloneVisitorNotMembers {
77387748
return super.visitArguments(node);
77397749
}
77407750
}
7751+
7752+
/// Returns `true` if [node] is not part of its parent member.
7753+
///
7754+
/// This computation is costly and should only be used in assertions to verify
7755+
/// that [node] has been removed from the AST.
7756+
bool isOrphaned(TreeNode node) {
7757+
TreeNode? parent = node;
7758+
Member? member;
7759+
while (parent != null) {
7760+
if (parent is Member) {
7761+
member = parent;
7762+
break;
7763+
}
7764+
parent = parent.parent;
7765+
}
7766+
if (member == null) {
7767+
return true;
7768+
}
7769+
_FindChildVisitor visitor = new _FindChildVisitor(node);
7770+
member.accept(visitor);
7771+
return !visitor.foundNode;
7772+
}
7773+
7774+
class _FindChildVisitor extends Visitor<void> with VisitorVoidMixin {
7775+
final TreeNode soughtNode;
7776+
bool foundNode = false;
7777+
7778+
_FindChildVisitor(this.soughtNode);
7779+
7780+
@override
7781+
void defaultNode(Node node) {
7782+
if (!foundNode) {
7783+
if (identical(node, soughtNode)) {
7784+
foundNode = true;
7785+
} else {
7786+
node.visitChildren(this);
7787+
}
7788+
}
7789+
}
7790+
}

pkg/front_end/lib/src/fasta/kernel/internal_ast.dart

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -828,8 +828,19 @@ class TypeAliasedConstructorInvocation extends ConstructorInvocation
828828
}
829829

830830
@override
831-
String toStringInternal() {
832-
return "";
831+
void toTextInternal(AstPrinter printer) {
832+
if (isConst) {
833+
printer.write('const ');
834+
} else {
835+
printer.write('new ');
836+
}
837+
printer.writeTypedefName(typeAliasBuilder.typedef.reference);
838+
printer.writeTypeArguments(arguments.types);
839+
if (target.name.text.isNotEmpty) {
840+
printer.write('.');
841+
printer.write(target.name.text);
842+
}
843+
printer.writeArguments(arguments, includeTypeArguments: false);
833844
}
834845
}
835846

@@ -857,8 +868,19 @@ class TypeAliasedFactoryInvocation extends StaticInvocation
857868
}
858869

859870
@override
860-
String toStringInternal() {
861-
return "";
871+
void toTextInternal(AstPrinter printer) {
872+
if (isConst) {
873+
printer.write('const ');
874+
} else {
875+
printer.write('new ');
876+
}
877+
printer.writeTypedefName(typeAliasBuilder.typedef.reference);
878+
printer.writeTypeArguments(arguments.types);
879+
if (target.name.text.isNotEmpty) {
880+
printer.write('.');
881+
printer.write(target.name.text);
882+
}
883+
printer.writeArguments(arguments, includeTypeArguments: false);
862884
}
863885
}
864886

pkg/front_end/test/spell_checking_list_tests.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ heuristics
519519
hi
520520
hints
521521
hits
522+
hkt
522523
home
523524
hoo
524525
hook

0 commit comments

Comments
 (0)