Skip to content

Commit 2f47565

Browse files
author
Dart CI
committed
Version 2.19.0-383.0.dev
Merge 3247ba2 into dev
2 parents fa65863 + 3247ba2 commit 2f47565

File tree

149 files changed

+3257
-625
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+3257
-625
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8539,6 +8539,17 @@ Message _withArgumentsNameNotFound(String name) {
85398539
arguments: {'name': name});
85408540
}
85418541

8542+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
8543+
const Code<Null> codeNamedFieldClashesWithPositionalFieldInRecord =
8544+
messageNamedFieldClashesWithPositionalFieldInRecord;
8545+
8546+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
8547+
const MessageCode messageNamedFieldClashesWithPositionalFieldInRecord =
8548+
const MessageCode("NamedFieldClashesWithPositionalFieldInRecord",
8549+
analyzerCodes: <String>["INVALID_FIELD_NAME"],
8550+
problemMessage:
8551+
r"""Record field names can't be a dollar sign followed by an integer when integer is the index of a positional field.""");
8552+
85428553
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
85438554
const Code<Null> codeNamedFunctionExpression = messageNamedFunctionExpression;
85448555

pkg/front_end/lib/src/fasta/builder/invalid_type_declaration_builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import 'type_declaration_builder.dart';
1818
class InvalidTypeDeclarationBuilder extends TypeDeclarationBuilderImpl
1919
with ErroneousMemberBuilderMixin {
2020
@override
21-
String get debugName => "InvalidTypeBuilder";
21+
String get debugName => "InvalidTypeDeclarationBuilder";
2222

2323
final LocatedMessage message;
2424

pkg/front_end/lib/src/fasta/builder/record_type_builder.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:kernel/src/unaliasing.dart';
99

1010
import '../fasta_codes.dart'
1111
show
12+
messageNamedFieldClashesWithPositionalFieldInRecord,
1213
messageObjectMemberNameUsedForRecordField,
1314
messageRecordFieldsCantBePrivate,
1415
messageSupertypeIsFunction,
@@ -17,6 +18,7 @@ import '../fasta_codes.dart'
1718
templateDuplicatedRecordTypeFieldNameContext;
1819
import '../kernel/implicit_field_type.dart';
1920
import '../source/source_library_builder.dart';
21+
import '../util/helpers.dart';
2022
import 'library_builder.dart';
2123
import 'metadata_builder.dart';
2224
import 'named_type_builder.dart';
@@ -200,6 +202,17 @@ abstract class RecordTypeBuilder extends TypeBuilder {
200202
hasErrors = true;
201203
continue;
202204
}
205+
if (tryParseRecordPositionalGetterName(
206+
name, positionalFields?.length ?? 0) !=
207+
null) {
208+
library.addProblem(
209+
messageNamedFieldClashesWithPositionalFieldInRecord,
210+
field.charOffset,
211+
name.length,
212+
fileUri);
213+
hasErrors = true;
214+
continue;
215+
}
203216
RecordTypeFieldBuilder? existingField = fieldsMap[name];
204217
if (existingField != null) {
205218
library.addProblem(

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import '../fasta_codes.dart'
7676
LocatedMessage,
7777
Message,
7878
Template,
79+
messageNamedFieldClashesWithPositionalFieldInRecord,
7980
noLength,
8081
templateDuplicatedRecordLiteralFieldName,
8182
templateDuplicatedRecordLiteralFieldNameContext,
@@ -4259,7 +4260,21 @@ class BodyBuilder extends StackListenerImpl
42594260
originalElementOrder.add(expression);
42604261
}
42614262
}
4263+
if (namedElements != null) {
4264+
for (NamedExpression element in namedElements.values) {
4265+
if (tryParseRecordPositionalGetterName(
4266+
element.name, positional.length) !=
4267+
null) {
4268+
libraryBuilder.addProblem(
4269+
messageNamedFieldClashesWithPositionalFieldInRecord,
4270+
element.fileOffset,
4271+
element.name.length,
4272+
uri);
4273+
}
4274+
}
4275+
}
42624276
}
4277+
42634278
push(new InternalRecordLiteral(
42644279
positional, named, namedElements, originalElementOrder,
42654280
isConst:

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

Lines changed: 100 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import 'package:kernel/type_algebra.dart' show containsTypeVariable;
88

99
import 'package:kernel/util/graph.dart' show Graph, computeStrongComponents;
1010

11+
import '../builder/builtin_type_declaration_builder.dart';
1112
import '../builder/class_builder.dart';
13+
import '../builder/extension_builder.dart';
1214
import '../builder/formal_parameter_builder.dart';
1315
import '../builder/function_type_builder.dart';
1416
import '../builder/invalid_type_declaration_builder.dart';
@@ -39,6 +41,11 @@ import '../fasta_codes.dart'
3941

4042
import '../kernel/utils.dart';
4143

44+
import '../problems.dart';
45+
import '../source/source_class_builder.dart';
46+
import '../source/source_extension_builder.dart';
47+
import '../source/source_type_alias_builder.dart';
48+
4249
/// Initial value for "variance" that is to be computed by the compiler.
4350
const int pendingVariance = -1;
4451

@@ -720,7 +727,9 @@ List<Object> findRawTypesWithInboundReferences(TypeBuilder? type) {
720727
/// generic types with inbound references in its bound. The second element of
721728
/// the triplet is the error message. The third element is the context.
722729
List<NonSimplicityIssue> getInboundReferenceIssues(
723-
List<TypeVariableBuilder> variables) {
730+
List<TypeVariableBuilder>? variables) {
731+
if (variables == null) return <NonSimplicityIssue>[];
732+
724733
List<NonSimplicityIssue> issues = <NonSimplicityIssue>[];
725734
for (TypeVariableBuilder variable in variables) {
726735
if (variable.bound != null) {
@@ -798,62 +807,54 @@ List<List<RawTypeCycleElement>> findRawTypePathsToDeclaration(
798807
[Set<TypeDeclarationBuilder>? visited]) {
799808
visited ??= new Set<TypeDeclarationBuilder>.identity();
800809
List<List<RawTypeCycleElement>> paths = <List<RawTypeCycleElement>>[];
810+
801811
if (start is NamedTypeBuilder) {
802-
TypeDeclarationBuilder? declaration = start.declaration;
812+
void visitTypeVariables(List<TypeVariableBuilder>? typeVariables) {
813+
if (typeVariables == null) return;
814+
815+
for (TypeVariableBuilder variable in typeVariables) {
816+
if (variable.bound != null) {
817+
for (List<RawTypeCycleElement> path
818+
in findRawTypePathsToDeclaration(variable.bound, end, visited)) {
819+
if (path.isNotEmpty) {
820+
paths.add(<RawTypeCycleElement>[
821+
new RawTypeCycleElement(start, null)
822+
]..addAll(path..first.typeVariable = variable));
823+
}
824+
}
825+
}
826+
}
827+
}
828+
803829
if (start.arguments == null) {
804-
if (start.declaration == end) {
830+
TypeDeclarationBuilder? declaration = start.declaration;
831+
if (declaration == end) {
805832
paths.add(<RawTypeCycleElement>[new RawTypeCycleElement(start, null)]);
806833
} else if (visited.add(start.declaration!)) {
807-
if (declaration is ClassBuilder && declaration.typeVariables != null) {
808-
for (TypeVariableBuilder variable in declaration.typeVariables!) {
809-
if (variable.bound != null) {
810-
for (List<RawTypeCycleElement> path
811-
in findRawTypePathsToDeclaration(
812-
variable.bound, end, visited)) {
813-
if (path.isNotEmpty) {
814-
paths.add(<RawTypeCycleElement>[
815-
new RawTypeCycleElement(start, null)
816-
]..addAll(path..first.typeVariable = variable));
817-
}
818-
}
819-
}
820-
}
834+
if (declaration is ClassBuilder) {
835+
visitTypeVariables(declaration.typeVariables);
821836
} else if (declaration is TypeAliasBuilder) {
822-
if (declaration.typeVariables != null) {
823-
for (TypeVariableBuilder variable in declaration.typeVariables!) {
824-
if (variable.bound != null) {
825-
for (List<RawTypeCycleElement> dependencyPath
826-
in findRawTypePathsToDeclaration(
827-
variable.bound, end, visited)) {
828-
if (dependencyPath.isNotEmpty) {
829-
paths.add(<RawTypeCycleElement>[
830-
new RawTypeCycleElement(start, null)
831-
]..addAll(dependencyPath..first.typeVariable = variable));
832-
}
833-
}
834-
}
835-
}
836-
}
837+
visitTypeVariables(declaration.typeVariables);
837838
if (declaration.type is FunctionTypeBuilder) {
838839
FunctionTypeBuilder type = declaration.type as FunctionTypeBuilder;
839-
if (type.typeVariables != null) {
840-
for (TypeVariableBuilder variable in type.typeVariables!) {
841-
if (variable.bound != null) {
842-
for (List<RawTypeCycleElement> dependencyPath
843-
in findRawTypePathsToDeclaration(
844-
variable.bound, end, visited)) {
845-
if (dependencyPath.isNotEmpty) {
846-
paths.add(<RawTypeCycleElement>[
847-
new RawTypeCycleElement(start, null)
848-
]..addAll(dependencyPath..first.typeVariable = variable));
849-
}
850-
}
851-
}
852-
}
853-
}
840+
visitTypeVariables(type.typeVariables);
854841
}
842+
} else if (declaration is ExtensionBuilder) {
843+
visitTypeVariables(declaration.typeParameters);
844+
} else if (declaration is TypeVariableBuilder) {
845+
// Do nothing. The type variable is handled by its parent declaration.
846+
} else if (declaration is BuiltinTypeDeclarationBuilder) {
847+
// Do nothing.
848+
} else if (declaration is InvalidTypeDeclarationBuilder) {
849+
// Do nothing.
850+
} else {
851+
unhandled(
852+
'$declaration (${declaration.runtimeType})',
853+
'findRawTypePathsToDeclaration',
854+
declaration?.charOffset ?? -1,
855+
declaration?.fileUri);
855856
}
856-
visited.remove(start.declaration);
857+
visited.remove(declaration);
857858
}
858859
} else {
859860
for (TypeBuilder argument in start.arguments!) {
@@ -883,6 +884,28 @@ List<List<RawTypeCycleElement>> findRawTypePathsToDeclaration(
883884
return paths;
884885
}
885886

887+
List<List<RawTypeCycleElement>> _findRawTypeCyclesFromTypeVariables(
888+
TypeDeclarationBuilder declaration,
889+
List<TypeVariableBuilder>? typeVariables) {
890+
if (typeVariables == null) {
891+
return const [];
892+
}
893+
894+
List<List<RawTypeCycleElement>> cycles = <List<RawTypeCycleElement>>[];
895+
for (TypeVariableBuilder variable in typeVariables) {
896+
if (variable.bound != null) {
897+
for (List<RawTypeCycleElement> dependencyPath
898+
in findRawTypePathsToDeclaration(variable.bound, declaration)) {
899+
if (dependencyPath.isNotEmpty) {
900+
dependencyPath.first.typeVariable = variable;
901+
cycles.add(dependencyPath);
902+
}
903+
}
904+
}
905+
}
906+
return cycles;
907+
}
908+
886909
/// Finds raw generic type cycles ending and starting with [declaration].
887910
///
888911
/// Returns list of found cycles consisting of [RawTypeCycleElement]s. The
@@ -893,51 +916,27 @@ List<List<RawTypeCycleElement>> findRawTypePathsToDeclaration(
893916
/// reporting.
894917
List<List<RawTypeCycleElement>> findRawTypeCycles(
895918
TypeDeclarationBuilder declaration) {
896-
List<List<RawTypeCycleElement>> cycles = <List<RawTypeCycleElement>>[];
897-
if (declaration is ClassBuilder && declaration.typeVariables != null) {
898-
for (TypeVariableBuilder variable in declaration.typeVariables!) {
899-
if (variable.bound != null) {
900-
for (List<RawTypeCycleElement> path
901-
in findRawTypePathsToDeclaration(variable.bound, declaration)) {
902-
if (path.isNotEmpty) {
903-
path.first.typeVariable = variable;
904-
cycles.add(path);
905-
}
906-
}
907-
}
908-
}
909-
} else if (declaration is TypeAliasBuilder) {
910-
if (declaration.typeVariables != null) {
911-
for (TypeVariableBuilder variable in declaration.typeVariables!) {
912-
if (variable.bound != null) {
913-
for (List<RawTypeCycleElement> dependencyPath
914-
in findRawTypePathsToDeclaration(variable.bound, declaration)) {
915-
if (dependencyPath.isNotEmpty) {
916-
dependencyPath.first.typeVariable = variable;
917-
cycles.add(dependencyPath);
918-
}
919-
}
920-
}
921-
}
922-
}
919+
if (declaration is SourceClassBuilder) {
920+
return _findRawTypeCyclesFromTypeVariables(
921+
declaration, declaration.typeVariables);
922+
} else if (declaration is SourceTypeAliasBuilder) {
923+
List<List<RawTypeCycleElement>> cycles = <List<RawTypeCycleElement>>[];
924+
cycles.addAll(_findRawTypeCyclesFromTypeVariables(
925+
declaration, declaration.typeVariables));
923926
if (declaration.type is FunctionTypeBuilder) {
924927
FunctionTypeBuilder type = declaration.type as FunctionTypeBuilder;
925-
if (type.typeVariables != null) {
926-
for (TypeVariableBuilder variable in type.typeVariables!) {
927-
if (variable.bound != null) {
928-
for (List<RawTypeCycleElement> dependencyPath
929-
in findRawTypePathsToDeclaration(variable.bound, declaration)) {
930-
if (dependencyPath.isNotEmpty) {
931-
dependencyPath.first.typeVariable = variable;
932-
cycles.add(dependencyPath);
933-
}
934-
}
935-
}
936-
}
937-
}
928+
cycles.addAll(
929+
_findRawTypeCyclesFromTypeVariables(declaration, type.typeVariables));
930+
return cycles;
938931
}
932+
} else if (declaration is SourceExtensionBuilder) {
933+
return _findRawTypeCyclesFromTypeVariables(
934+
declaration, declaration.typeParameters);
935+
} else {
936+
unhandled('$declaration (${declaration.runtimeType})', 'findRawTypeCycles',
937+
declaration.charOffset, declaration.fileUri);
939938
}
940-
return cycles;
939+
return const [];
941940
}
942941

943942
/// Converts raw generic type [cycles] for [declaration] into reportable issues.
@@ -1012,11 +1011,18 @@ List<NonSimplicityIssue> getNonSimplicityIssuesForDeclaration(
10121011
TypeDeclarationBuilder declaration,
10131012
{bool performErrorRecovery = true}) {
10141013
List<NonSimplicityIssue> issues = <NonSimplicityIssue>[];
1015-
if (declaration is ClassBuilder && declaration.typeVariables != null) {
1016-
issues.addAll(getInboundReferenceIssues(declaration.typeVariables!));
1017-
} else if (declaration is TypeAliasBuilder &&
1018-
declaration.typeVariables != null) {
1019-
issues.addAll(getInboundReferenceIssues(declaration.typeVariables!));
1014+
if (declaration is SourceClassBuilder) {
1015+
issues.addAll(getInboundReferenceIssues(declaration.typeVariables));
1016+
} else if (declaration is SourceTypeAliasBuilder) {
1017+
issues.addAll(getInboundReferenceIssues(declaration.typeVariables));
1018+
} else if (declaration is SourceExtensionBuilder) {
1019+
issues.addAll(getInboundReferenceIssues(declaration.typeParameters));
1020+
} else {
1021+
unhandled(
1022+
'$declaration (${declaration.runtimeType})',
1023+
'getNonSimplicityIssuesForDeclaration',
1024+
declaration.charOffset,
1025+
declaration.fileUri);
10201026
}
10211027
List<List<RawTypeCycleElement>> cyclesToReport =
10221028
<List<RawTypeCycleElement>>[];

pkg/front_end/lib/src/fasta/type_inference/inference_visitor_base.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import '../names.dart';
4040
import '../problems.dart' show internalProblem, unhandled;
4141
import '../source/source_constructor_builder.dart';
4242
import '../source/source_library_builder.dart' show SourceLibraryBuilder;
43+
import '../util/helpers.dart';
4344
import 'closure_context.dart';
4445
import 'inference_helper.dart' show InferenceHelper;
4546
import 'inference_results.dart';
@@ -4032,6 +4033,15 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
40324033
}
40334034
}
40344035
}
4036+
int? index = tryParseRecordPositionalGetterName(
4037+
text, recordType.positional.length);
4038+
if (index != null) {
4039+
DartType fieldType = recordType.positional[index];
4040+
result = new ExpressionInferenceResult(
4041+
fieldType,
4042+
new RecordIndexGet(receiver, recordType, index)
4043+
..fileOffset = fileOffset);
4044+
}
40354045
if (result == null) {
40364046
for (NamedType field in recordType.named) {
40374047
if (field.name == text) {

pkg/front_end/lib/src/fasta/util/helpers.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,20 @@ bool isDartCoreRecord(DartType type) {
2929
targetClass.enclosingLibrary.importUri.scheme == "dart" &&
3030
targetClass.enclosingLibrary.importUri.path == "core";
3131
}
32+
33+
int? tryParseRecordPositionalGetterName(String name, int positionalFieldCount) {
34+
if (name.startsWith(r"$")) {
35+
String suffix = name.substring(1);
36+
int? impliedIndex = int.tryParse(suffix);
37+
if (impliedIndex != null &&
38+
impliedIndex >= 0 &&
39+
impliedIndex < positionalFieldCount &&
40+
suffix == "${impliedIndex}") {
41+
return impliedIndex;
42+
} else {
43+
return null;
44+
}
45+
} else {
46+
return null;
47+
}
48+
}

0 commit comments

Comments
 (0)