Skip to content

Commit

Permalink
Version 3.2.0-224.0.dev
Browse files Browse the repository at this point in the history
Merge 6e1ba9d into dev
  • Loading branch information
Dart CI committed Oct 3, 2023
2 parents a4a29db + 6e1ba9d commit 86d84b3
Show file tree
Hide file tree
Showing 61 changed files with 1,327 additions and 1,044 deletions.
99 changes: 50 additions & 49 deletions pkg/_fe_analyzer_shared/lib/src/messages/codes_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2894,55 +2894,6 @@ Message _withArgumentsDuplicatedModifier(Token token) {
arguments: {'lexeme': token});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Template<
Message Function(
String
name)> templateDuplicatedNamePreviouslyUsed = const Template<
Message Function(String name)>("DuplicatedNamePreviouslyUsed",
problemMessageTemplate:
r"""Can't declare '#name' because it was already used in this scope.""",
withArguments: _withArgumentsDuplicatedNamePreviouslyUsed);

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Message Function(String name)> codeDuplicatedNamePreviouslyUsed =
const Code<Message Function(String name)>("DuplicatedNamePreviouslyUsed",
analyzerCodes: <String>["REFERENCED_BEFORE_DECLARATION"]);

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Message _withArgumentsDuplicatedNamePreviouslyUsed(String name) {
if (name.isEmpty) throw 'No name provided';
name = demangleMixinApplicationName(name);
return new Message(codeDuplicatedNamePreviouslyUsed,
problemMessage:
"""Can't declare '${name}' because it was already used in this scope.""",
arguments: {'name': name});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Template<Message Function(String name)>
templateDuplicatedNamePreviouslyUsedCause =
const Template<Message Function(String name)>(
"DuplicatedNamePreviouslyUsedCause",
problemMessageTemplate: r"""Previous use of '#name'.""",
withArguments: _withArgumentsDuplicatedNamePreviouslyUsedCause);

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Message Function(String name)>
codeDuplicatedNamePreviouslyUsedCause =
const Code<Message Function(String name)>(
"DuplicatedNamePreviouslyUsedCause",
severity: Severity.context);

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Message _withArgumentsDuplicatedNamePreviouslyUsedCause(String name) {
if (name.isEmpty) throw 'No name provided';
name = demangleMixinApplicationName(name);
return new Message(codeDuplicatedNamePreviouslyUsedCause,
problemMessage: """Previous use of '${name}'.""",
arguments: {'name': name});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Template<Message Function(String name)> templateDuplicatedNamedArgument =
const Template<Message Function(String name)>("DuplicatedNamedArgument",
Expand Down Expand Up @@ -9267,6 +9218,56 @@ const MessageCode messageLoadLibraryTakesNoArguments = const MessageCode(
analyzerCodes: <String>["LOAD_LIBRARY_TAKES_NO_ARGUMENTS"],
problemMessage: r"""'loadLibrary' takes no arguments.""");

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Template<
Message Function(
String
name)> templateLocalVariableUsedBeforeDeclared = const Template<
Message Function(String name)>("LocalVariableUsedBeforeDeclared",
problemMessageTemplate:
r"""Local variable '#name' can't be referenced before it is declared.""",
withArguments: _withArgumentsLocalVariableUsedBeforeDeclared);

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Message Function(String name)> codeLocalVariableUsedBeforeDeclared =
const Code<Message Function(String name)>("LocalVariableUsedBeforeDeclared",
analyzerCodes: <String>["REFERENCED_BEFORE_DECLARATION"]);

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Message _withArgumentsLocalVariableUsedBeforeDeclared(String name) {
if (name.isEmpty) throw 'No name provided';
name = demangleMixinApplicationName(name);
return new Message(codeLocalVariableUsedBeforeDeclared,
problemMessage:
"""Local variable '${name}' can't be referenced before it is declared.""",
arguments: {'name': name});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Template<Message Function(String name)>
templateLocalVariableUsedBeforeDeclaredContext =
const Template<Message Function(String name)>(
"LocalVariableUsedBeforeDeclaredContext",
problemMessageTemplate:
r"""This is the declaration of the variable '#name'.""",
withArguments: _withArgumentsLocalVariableUsedBeforeDeclaredContext);

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Code<Message Function(String name)>
codeLocalVariableUsedBeforeDeclaredContext =
const Code<Message Function(String name)>(
"LocalVariableUsedBeforeDeclaredContext",
severity: Severity.context);

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
Message _withArgumentsLocalVariableUsedBeforeDeclaredContext(String name) {
if (name.isEmpty) throw 'No name provided';
name = demangleMixinApplicationName(name);
return new Message(codeLocalVariableUsedBeforeDeclaredContext,
problemMessage: """This is the declaration of the variable '${name}'.""",
arguments: {'name': name});
}

// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
const Template<
Message Function(
Expand Down
36 changes: 22 additions & 14 deletions pkg/front_end/lib/src/fasta/kernel/body_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ import '../fasta_codes.dart'
noLength,
templateDuplicatedRecordLiteralFieldName,
templateDuplicatedRecordLiteralFieldNameContext,
templateExperimentNotEnabledOffByDefault;
templateExperimentNotEnabledOffByDefault,
templateLocalVariableUsedBeforeDeclared,
templateLocalVariableUsedBeforeDeclaredContext;
import '../identifiers.dart'
show
Identifier,
Expand Down Expand Up @@ -746,17 +748,25 @@ class BodyBuilder extends StackListenerImpl
if (isGuardScope(scope)) {
(declaredInCurrentGuard ??= {}).add(variable);
}
LocatedMessage? context = scope.declare(
variable.name!, new VariableBuilderImpl(variable, uri), uri);
if (context != null) {
String variableName = variable.name!;
List<int>? previousOffsets = scope.declare(
variableName, new VariableBuilderImpl(variable, uri), uri);
if (previousOffsets != null && previousOffsets.isNotEmpty) {
// This case is different from the above error. In this case, the problem
// is using `x` before it's declared: `{ var x; { print(x); var x;
// }}`. In this case, we want two errors, the `x` in `print(x)` and the
// second (or innermost declaration) of `x`.
wrapVariableInitializerInError(
variable,
fasta.templateDuplicatedNamePreviouslyUsed,
<LocatedMessage>[context]);
for (int previousOffset in previousOffsets) {
addProblem(
templateLocalVariableUsedBeforeDeclared.withArguments(variableName),
previousOffset,
variableName.length,
context: <LocatedMessage>[
templateLocalVariableUsedBeforeDeclaredContext
.withArguments(variableName)
.withLocation(uri, variable.fileOffset, variableName.length)
]);
}
}
}

Expand Down Expand Up @@ -8114,7 +8124,7 @@ class BodyBuilder extends StackListenerImpl
scope.kind == ScopeKind.jointVariables,
"Expected the current scope to be of kind '${ScopeKind.switchCase}' "
"or '${ScopeKind.jointVariables}', but got '${scope.kind}.");
Map<String, int>? usedNamesOffsets = scope.usedNames;
Map<String, List<int>>? usedNamesOffsets = scope.usedNames;

bool hasDefaultOrLabels = defaultKeyword != null || labelCount > 0;

Expand All @@ -8124,10 +8134,9 @@ class BodyBuilder extends StackListenerImpl
usedJointPatternVariables = [];
Map<VariableDeclaration, int> firstUseOffsets = {};
for (VariableDeclaration variable in jointPatternVariables) {
int? firstUseOffset = usedNamesOffsets?[variable.name!];
if (firstUseOffset != null) {
if (usedNamesOffsets?[variable.name!] case [int offset, ...]) {
usedJointPatternVariables.add(variable);
firstUseOffsets[variable] = firstUseOffset;
firstUseOffsets[variable] = offset;
}
}
if (jointPatternVariablesWithMismatchingFinality != null ||
Expand Down Expand Up @@ -8190,8 +8199,7 @@ class BodyBuilder extends StackListenerImpl
for (VariableDeclaration variable
in patternGuard.pattern.declaredVariables) {
String variableName = variable.name!;
int? offset = usedNamesOffsets[variableName];
if (offset != null) {
if (usedNamesOffsets[variableName] case [int offset, ...]) {
addProblem(
fasta.templateJointPatternVariableWithLabelDefault
.withArguments(variableName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,15 @@ abstract class CombinedMemberSignatureBase<T> {
for (int i = 0; i < typeParameterCount; i++) {
DartType typeParameterBound = typeParameters[i].bound;
DartType signatureTypeParameterBound =
instantiator.visit(signatureTypeParameters[i].bound);
instantiator.substitute(signatureTypeParameters[i].bound);
if (!_types
.performNullabilityAwareMutualSubtypesCheck(
typeParameterBound, signatureTypeParameterBound)
.isSubtypeWhenUsingNullabilities()) {
return null;
}
}
return instantiator.visit(type.withoutTypeParameters);
return instantiator.substitute(type.withoutTypeParameters);
} else if (typeParameterCount != 0) {
return null;
}
Expand Down
16 changes: 7 additions & 9 deletions pkg/front_end/lib/src/fasta/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class Scope extends MutableScope {

Map<String, JumpTarget>? forwardDeclaredLabels;

Map<String, int>? usedNames;
Map<String, List<int>>? usedNames;

Scope(
{required ScopeKind kind,
Expand Down Expand Up @@ -496,10 +496,10 @@ class Scope extends MutableScope {

void recordUse(String name, int charOffset) {
if (isModifiable) {
usedNames ??= <String, int>{};
usedNames ??= <String, List<int>>{};
// Don't use putIfAbsent to avoid the context allocation needed
// for the closure.
usedNames![name] ??= charOffset;
(usedNames![name] ??= []).add(charOffset);
}
}

Expand Down Expand Up @@ -646,13 +646,11 @@ class Scope extends MutableScope {
/// that can be used as context for reporting a compile-time error about
/// [name] being used before its declared. [fileUri] is used to bind the
/// location of this message.
LocatedMessage? declare(String name, Builder builder, Uri fileUri) {
List<int>? declare(String name, Builder builder, Uri fileUri) {
if (isModifiable) {
int? offset = usedNames?[name];
if (offset != null) {
return templateDuplicatedNamePreviouslyUsedCause
.withArguments(name)
.withLocation(fileUri, offset, name.length);
List<int>? previousOffsets = usedNames?[name];
if (previousOffsets != null && previousOffsets.isNotEmpty) {
return previousOffsets;
}
(_local ??= {})[name] = builder;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,8 @@ class RedirectingFactoryBuilder extends SourceFactoryBuilder {
for (int i = 0; i < targetFunctionType.typeParameters.length; i++) {
StructuralParameter typeParameter =
targetFunctionType.typeParameters[i];
DartType typeParameterBound = instantiator.visit(typeParameter.bound);
DartType typeParameterBound =
instantiator.substitute(typeParameter.bound);
DartType typeArgument = typeArguments[i];
// Check whether the [typeArgument] respects the bounds of
// [typeParameter].
Expand Down Expand Up @@ -688,7 +689,7 @@ class RedirectingFactoryBuilder extends SourceFactoryBuilder {
// Substitute if necessary.
targetFunctionType = instantiator == null
? targetFunctionType
: (instantiator.visit(targetFunctionType.withoutTypeParameters)
: (instantiator.substitute(targetFunctionType.withoutTypeParameters)
as FunctionType);

return hasProblem ? null : targetFunctionType;
Expand Down
4 changes: 4 additions & 0 deletions pkg/front_end/lib/src/fasta/source/source_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3152,6 +3152,8 @@ class List<E> extends Iterable<E> {
void add(E element) {}
void addAll(Iterable<E> iterable) {}
E operator [](int index) => null;
int get length => 0;
List<E> sublist(int start, [int? end]) => this;
}
class _GrowableList<E> implements List<E> {
Expand Down Expand Up @@ -3254,6 +3256,8 @@ class int extends num {
class num {
num operator -() => this;
num operator -(num other) => this;
bool operator >=(num other) => false;
}
class Function {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1612,7 +1612,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
namedParameters: calleeType.namedParameters,
typeParameters: targetTypeParameters);
targetFunctionType =
extensionInstantiator.visit(targetFunctionType) as FunctionType;
extensionInstantiator.substitute(targetFunctionType) as FunctionType;
ArgumentsImpl targetArguments = new ArgumentsImpl(
arguments.positional.skip(1).toList(),
named: arguments.named,
Expand Down Expand Up @@ -1672,10 +1672,14 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
// type parameters for the callee (see dartbug.com/31759).
// TODO(paulberry): is it possible to find a narrower set of circumstances
// in which me must do this, to avoid a performance regression?
FreshStructuralParameters fresh =
getFreshStructuralParameters(calleeTypeParameters);
calleeType = fresh.applyToFunctionType(calleeType);
calleeTypeParameters = fresh.freshTypeParameters;
if (calleeTypeParameters.isNotEmpty) {
FreshStructuralParameters fresh =
getFreshStructuralParameters(calleeTypeParameters);
calleeType = fresh.applyToFunctionType(calleeType);
calleeTypeParameters = fresh.freshTypeParameters;
} else {
calleeTypeParameters = const <StructuralParameter>[];
}
}

List<DartType>? explicitTypeArguments = getExplicitTypeArguments(arguments);
Expand Down Expand Up @@ -1777,8 +1781,9 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
ExpressionInferenceResult inferArgument(
DartType formalType, Expression argumentExpression,
{required bool isNamed}) {
DartType inferredFormalType =
instantiator != null ? instantiator.visit(formalType) : formalType;
DartType inferredFormalType = instantiator != null
? instantiator.substitute(formalType)
: formalType;
if (!isNamed) {
if (isSpecialCasedBinaryOperator) {
inferredFormalType =
Expand Down Expand Up @@ -2037,7 +2042,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
for (int i = 0; i < formalTypes.length; i++) {
DartType formalType = formalTypes[i];
DartType expectedType = instantiator != null
? instantiator.visit(formalType)
? instantiator.substitute(formalType)
: formalType;
DartType actualType = actualTypes[i];
Expression expression;
Expand Down Expand Up @@ -2078,8 +2083,8 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
}
DartType inferredType;
if (instantiator != null) {
calleeType =
instantiator.visit(calleeType.withoutTypeParameters) as FunctionType;
calleeType = instantiator.substitute(calleeType.withoutTypeParameters)
as FunctionType;
}
inferredType = calleeType.returnType;
assert(
Expand Down Expand Up @@ -2193,7 +2198,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
DartType inferredType;
if (formalTypesFromContext[i] != null) {
inferredType = computeGreatestClosure2(
instantiator?.visit(formalTypesFromContext[i]!) ??
instantiator?.substitute(formalTypesFromContext[i]!) ??
formalTypesFromContext[i]!);
if (typeSchemaEnvironment.isSubtypeOf(
inferredType,
Expand Down Expand Up @@ -2255,7 +2260,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
// accordingly if the closure is declared with `async`, `async*`, or
// `sync*`.
if (returnContext is! UnknownType) {
returnContext = instantiator?.visit(returnContext) ?? returnContext;
returnContext = instantiator?.substitute(returnContext) ?? returnContext;
}

// Apply type inference to `B` in return context `N’`, with any references
Expand Down Expand Up @@ -3565,7 +3570,7 @@ abstract class InferenceVisitorBase implements InferenceVisitor {
FunctionTypeInstantiator instantiator =
new FunctionTypeInstantiator.fromIterables(
typeParameters, inferredTypes);
tearoffType = instantiator.visit(instantiatedType);
tearoffType = instantiator.substitute(instantiatedType);
return new ImplicitInstantiation(
inferredTypes, functionType, tearoffType);
}
Expand Down
Loading

0 comments on commit 86d84b3

Please sign in to comment.