Skip to content

Commit 1123958

Browse files
chloestefantsovaCommit Bot
authored and
Commit Bot
committed
Revert "[cfe] Remove coercions for super parameters"
This reverts commit 61465fb. Reason for revert: potential future Flutter breakages. Original change's description: > [cfe] Remove coercions for super parameters > > Part of #47525 > > Change-Id: Iadb2f0125318edd73ab84e5b1a9cafae098ec618 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239081 > Reviewed-by: Johnni Winther <[email protected]> > Commit-Queue: Chloe Stefantsova <[email protected]> # Not skipping CQ checks because original CL landed > 1 day ago. Change-Id: I1f6321af1a3290f00920d056c68dfb9b68dd5e9d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239423 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Alexander Aprelev <[email protected]>
1 parent b1fbe0c commit 1123958

13 files changed

+8
-1400
lines changed

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1854,7 +1854,6 @@ class BodyBuilder extends StackListenerImpl
18541854

18551855
List<Expression>? positionalSuperParametersAsArguments;
18561856
List<NamedExpression>? namedSuperParametersAsArguments;
1857-
Set<String>? namedSuperParameterNames;
18581857
if (formals != null) {
18591858
for (FormalParameterBuilder formal in formals) {
18601859
if (formal.isSuperInitializingFormal) {
@@ -1866,7 +1865,6 @@ class BodyBuilder extends StackListenerImpl
18661865
forNullGuardedAccess: false)
18671866
..fileOffset = formal.charOffset)
18681867
..fileOffset = formal.charOffset);
1869-
(namedSuperParameterNames ??= <String>{}).add(formal.name);
18701868
} else {
18711869
(positionalSuperParametersAsArguments ??= <Expression>[]).add(
18721870
new VariableGetImpl(formal.variable!,
@@ -1888,7 +1886,7 @@ class BodyBuilder extends StackListenerImpl
18881886
superInitializer.fileOffset, noLength))
18891887
..parent = constructor;
18901888
} else if (libraryBuilder.enableSuperParametersInLibrary) {
1891-
ArgumentsImpl arguments = superInitializer.arguments as ArgumentsImpl;
1889+
Arguments arguments = superInitializer.arguments;
18921890

18931891
if (positionalSuperParametersAsArguments != null) {
18941892
if (arguments.positional.isNotEmpty) {
@@ -1906,14 +1904,12 @@ class BodyBuilder extends StackListenerImpl
19061904
} else {
19071905
arguments.positional.addAll(positionalSuperParametersAsArguments);
19081906
setParents(positionalSuperParametersAsArguments, arguments);
1909-
arguments.positionalAreSuperParameters = true;
19101907
}
19111908
}
19121909
if (namedSuperParametersAsArguments != null) {
19131910
// TODO(cstefantsova): Report name conflicts.
19141911
arguments.named.addAll(namedSuperParametersAsArguments);
19151912
setParents(namedSuperParametersAsArguments, arguments);
1916-
arguments.namedSuperParameterNames = namedSuperParameterNames;
19171913
}
19181914
}
19191915
} else if (initializers.last is RedirectingInitializer) {
@@ -1962,7 +1958,7 @@ class BodyBuilder extends StackListenerImpl
19621958
/// >unless the enclosing class is class Object.
19631959
Constructor? superTarget = lookupConstructor(emptyName, isSuper: true);
19641960
Initializer initializer;
1965-
ArgumentsImpl arguments;
1961+
Arguments arguments;
19661962
List<Expression>? positionalArguments;
19671963
List<NamedExpression>? namedArguments;
19681964
if (libraryBuilder.enableSuperParametersInLibrary) {
@@ -1980,19 +1976,13 @@ class BodyBuilder extends StackListenerImpl
19801976
forNullGuardedAccess: false)
19811977
]);
19821978
}
1983-
19841979
if (positionalArguments != null || namedArguments != null) {
19851980
arguments = forest.createArguments(
19861981
noLocation, positionalArguments ?? <Expression>[],
19871982
named: namedArguments);
19881983
} else {
19891984
arguments = forest.createArgumentsEmpty(noLocation);
19901985
}
1991-
1992-
arguments.positionalAreSuperParameters =
1993-
positionalSuperParametersAsArguments != null;
1994-
arguments.namedSuperParameterNames = namedSuperParameterNames;
1995-
19961986
if (superTarget == null ||
19971987
checkArgumentsForFunction(superTarget.function, arguments,
19981988
builder.charOffset, const <TypeParameter>[]) !=

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -493,17 +493,6 @@ class ArgumentsImpl extends Arguments {
493493

494494
List<Object?>? argumentsOriginalOrder;
495495

496-
/// True if the arguments are passed to the super-constructor in a
497-
/// super-initializer, and the positional parameters are super-initializer
498-
/// parameters. It is true that either all of the positional parameters are
499-
/// super-initializer parameters or none of them, so a simple boolean
500-
/// accurately reflects the state.
501-
bool positionalAreSuperParameters = false;
502-
503-
/// Names of the named positional parameters. If none of the parameters are
504-
/// super-positional, the field is null.
505-
Set<String>? namedSuperParameterNames;
506-
507496
ArgumentsImpl.internal(
508497
{required List<Expression> positional,
509498
required List<DartType>? types,

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

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,6 @@ class TypeInferrerImpl implements TypeInferrer {
494494
DartType? declaredContextType,
495495
DartType? runtimeCheckedType,
496496
bool isVoidAllowed: false,
497-
bool coerceExpression: true,
498497
Template<Message Function(DartType, DartType, bool)>? errorTemplate,
499498
Template<Message Function(DartType, DartType, bool)>?
500499
nullabilityErrorTemplate,
@@ -510,7 +509,6 @@ class TypeInferrerImpl implements TypeInferrer {
510509
declaredContextType: declaredContextType,
511510
runtimeCheckedType: runtimeCheckedType,
512511
isVoidAllowed: isVoidAllowed,
513-
coerceExpression: coerceExpression,
514512
errorTemplate: errorTemplate,
515513
nullabilityErrorTemplate: nullabilityErrorTemplate,
516514
nullabilityNullErrorTemplate: nullabilityNullErrorTemplate,
@@ -529,7 +527,6 @@ class TypeInferrerImpl implements TypeInferrer {
529527
DartType? declaredContextType,
530528
DartType? runtimeCheckedType,
531529
bool isVoidAllowed: false,
532-
bool coerceExpression: true,
533530
Template<Message Function(DartType, DartType, bool)>? errorTemplate,
534531
Template<Message Function(DartType, DartType, bool)>?
535532
nullabilityErrorTemplate,
@@ -581,8 +578,7 @@ class TypeInferrerImpl implements TypeInferrer {
581578
contextType, inferenceResult.inferredType,
582579
isNonNullableByDefault: isNonNullableByDefault,
583580
isVoidAllowed: isVoidAllowed,
584-
isExpressionTypePrecise: preciseTypeErrorTemplate != null,
585-
coerceExpression: coerceExpression);
581+
isExpressionTypePrecise: preciseTypeErrorTemplate != null);
586582

587583
if (assignabilityResult.needsTearOff) {
588584
TypedTearoff typedTearoff = _tearOffCall(inferenceResult.expression,
@@ -786,8 +782,7 @@ class TypeInferrerImpl implements TypeInferrer {
786782
DartType contextType, DartType expressionType,
787783
{required bool isNonNullableByDefault,
788784
required bool isVoidAllowed,
789-
required bool isExpressionTypePrecise,
790-
required bool coerceExpression}) {
785+
required bool isExpressionTypePrecise}) {
791786
// ignore: unnecessary_null_comparison
792787
assert(isNonNullableByDefault != null);
793788
// ignore: unnecessary_null_comparison
@@ -799,7 +794,7 @@ class TypeInferrerImpl implements TypeInferrer {
799794
// should tear off `.call`.
800795
// TODO(paulberry): use resolveTypeParameter. See findInterfaceMember.
801796
bool needsTearoff = false;
802-
if (coerceExpression && expressionType is InterfaceType) {
797+
if (expressionType is InterfaceType) {
803798
Class classNode = expressionType.classNode;
804799
Member? callMember =
805800
classHierarchy.getInterfaceMember(classNode, callName);
@@ -818,7 +813,7 @@ class TypeInferrerImpl implements TypeInferrer {
818813
}
819814
}
820815
ImplicitInstantiation? implicitInstantiation;
821-
if (coerceExpression && libraryBuilder.enableConstructorTearOffsInLibrary) {
816+
if (libraryBuilder.enableConstructorTearOffsInLibrary) {
822817
implicitInstantiation =
823818
computeImplicitInstantiation(expressionType, contextType);
824819
if (implicitInstantiation != null) {
@@ -872,15 +867,8 @@ class TypeInferrerImpl implements TypeInferrer {
872867
return const AssignabilityResult(AssignabilityKind.unassignablePrecise,
873868
needsTearOff: false);
874869
}
875-
876-
if (coerceExpression) {
877-
// Insert an implicit downcast.
878-
return new AssignabilityResult(AssignabilityKind.assignableCast,
879-
needsTearOff: needsTearoff,
880-
implicitInstantiation: implicitInstantiation);
881-
}
882-
883-
return new AssignabilityResult(AssignabilityKind.unassignable,
870+
// Insert an implicit downcast.
871+
return new AssignabilityResult(AssignabilityKind.assignableCast,
884872
needsTearOff: needsTearoff,
885873
implicitInstantiation: implicitInstantiation);
886874
}
@@ -2630,23 +2618,17 @@ class TypeInferrerImpl implements TypeInferrer {
26302618
DartType actualType = actualTypes![i];
26312619
Expression expression;
26322620
NamedExpression? namedExpression;
2633-
bool coerceExpression;
26342621
if (i < numPositionalArgs) {
26352622
expression = arguments.positional[positionalShift + i];
26362623
positionalArgumentTypes.add(actualType);
2637-
coerceExpression = !arguments.positionalAreSuperParameters;
26382624
} else {
26392625
namedExpression = arguments.named[i - numPositionalArgs];
26402626
expression = namedExpression.value;
26412627
namedArgumentTypes
26422628
.add(new NamedType(namedExpression.name, actualType));
2643-
coerceExpression = !(arguments.namedSuperParameterNames
2644-
?.contains(namedExpression.name) ??
2645-
false);
26462629
}
26472630
expression = ensureAssignable(expectedType, actualType, expression,
26482631
isVoidAllowed: expectedType is VoidType,
2649-
coerceExpression: coerceExpression,
26502632
// TODO(johnniwinther): Specialize message for operator
26512633
// invocations.
26522634
errorTemplate: templateArgumentTypeNotAssignable,

pkg/front_end/test/spell_checking_list_common.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ account
4747
accounted
4848
accumulate
4949
accurate
50-
accurately
5150
achieve
5251
act
5352
acting
@@ -490,7 +489,6 @@ closure
490489
closures
491490
clue
492491
code
493-
coerce
494492
coincides
495493
coinductively
496494
collapses

pkg/front_end/testcases/super_parameters/no_coercions.dart

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)