Skip to content

Commit e18977e

Browse files
johnniwintherCommit Bot
authored and
Commit Bot
committed
[cfe] Report error for missing concrete super target
In response to #47406 The error is currently not reported if the mixin declaration is from an outline dill. Change-Id: I94a61d6409d0c238614d9f377b5f324153360bc6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/249184 Reviewed-by: Sigmund Cherem <sigmund@google.com> Reviewed-by: Jens Johansen <jensj@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com>
1 parent 0113970 commit e18977e

File tree

52 files changed

+8303
-41
lines changed

Some content is hidden

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

52 files changed

+8303
-41
lines changed

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

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7820,6 +7820,101 @@ const MessageCode messageMissingTypedefParameters = const MessageCode(
78207820
problemMessage: r"""A typedef needs an explicit list of parameters.""",
78217821
correctionMessage: r"""Try adding a parameter list to the typedef.""");
78227822

7823+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
7824+
const Template<
7825+
Message Function(
7826+
String
7827+
name)> templateMixinApplicationNoConcreteGetter = const Template<
7828+
Message Function(String name)>(
7829+
problemMessageTemplate:
7830+
r"""The class doesn't have a concrete implementation of the super-accessed member '#name'.""",
7831+
withArguments: _withArgumentsMixinApplicationNoConcreteGetter);
7832+
7833+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
7834+
const Code<Message Function(String name)> codeMixinApplicationNoConcreteGetter =
7835+
const Code<Message Function(String name)>(
7836+
"MixinApplicationNoConcreteGetter",
7837+
analyzerCodes: <String>[
7838+
"MIXIN_APPLICATION_NO_CONCRETE_SUPER_INVOKED_MEMBER"
7839+
]);
7840+
7841+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
7842+
Message _withArgumentsMixinApplicationNoConcreteGetter(String name) {
7843+
if (name.isEmpty) throw 'No name provided';
7844+
name = demangleMixinApplicationName(name);
7845+
return new Message(codeMixinApplicationNoConcreteGetter,
7846+
problemMessage:
7847+
"""The class doesn't have a concrete implementation of the super-accessed member '${name}'.""",
7848+
arguments: {'name': name});
7849+
}
7850+
7851+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
7852+
const Code<Null> codeMixinApplicationNoConcreteMemberContext =
7853+
messageMixinApplicationNoConcreteMemberContext;
7854+
7855+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
7856+
const MessageCode messageMixinApplicationNoConcreteMemberContext =
7857+
const MessageCode("MixinApplicationNoConcreteMemberContext",
7858+
severity: Severity.context,
7859+
problemMessage:
7860+
r"""This is the super-access that doesn't have a concrete target.""");
7861+
7862+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
7863+
const Template<
7864+
Message Function(
7865+
String
7866+
name)> templateMixinApplicationNoConcreteMethod = const Template<
7867+
Message Function(String name)>(
7868+
problemMessageTemplate:
7869+
r"""The class doesn't have a concrete implementation of the super-invoked member '#name'.""",
7870+
withArguments: _withArgumentsMixinApplicationNoConcreteMethod);
7871+
7872+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
7873+
const Code<Message Function(String name)> codeMixinApplicationNoConcreteMethod =
7874+
const Code<Message Function(String name)>(
7875+
"MixinApplicationNoConcreteMethod",
7876+
analyzerCodes: <String>[
7877+
"MIXIN_APPLICATION_NO_CONCRETE_SUPER_INVOKED_MEMBER"
7878+
]);
7879+
7880+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
7881+
Message _withArgumentsMixinApplicationNoConcreteMethod(String name) {
7882+
if (name.isEmpty) throw 'No name provided';
7883+
name = demangleMixinApplicationName(name);
7884+
return new Message(codeMixinApplicationNoConcreteMethod,
7885+
problemMessage:
7886+
"""The class doesn't have a concrete implementation of the super-invoked member '${name}'.""",
7887+
arguments: {'name': name});
7888+
}
7889+
7890+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
7891+
const Template<
7892+
Message Function(
7893+
String
7894+
name)> templateMixinApplicationNoConcreteSetter = const Template<
7895+
Message Function(String name)>(
7896+
problemMessageTemplate:
7897+
r"""The class doesn't have a concrete implementation of the super-accessed setter '#name'.""",
7898+
withArguments: _withArgumentsMixinApplicationNoConcreteSetter);
7899+
7900+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
7901+
const Code<Message Function(String name)> codeMixinApplicationNoConcreteSetter =
7902+
const Code<Message Function(String name)>(
7903+
"MixinApplicationNoConcreteSetter",
7904+
analyzerCodes: <String>[
7905+
"MIXIN_APPLICATION_NO_CONCRETE_SUPER_INVOKED_MEMBER"
7906+
]);
7907+
7908+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
7909+
Message _withArgumentsMixinApplicationNoConcreteSetter(String name) {
7910+
if (name.isEmpty) throw 'No name provided';
7911+
name = demangleMixinApplicationName(name);
7912+
return new Message(codeMixinApplicationNoConcreteSetter,
7913+
problemMessage:
7914+
"""The class doesn't have a concrete implementation of the super-accessed setter '${name}'.""",
7915+
arguments: {'name': name});
7916+
}
7917+
78237918
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
78247919
const Code<Null> codeMixinDeclaresConstructor = messageMixinDeclaresConstructor;
78257920

pkg/compiler/lib/src/js_model/element_map_impl.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap {
772772
//
773773
// so we need get the superclasses from the on-clause, A, B, and C,
774774
// through [superclassConstraints].
775-
for (ir.Supertype constraint in node.superclassConstraints()) {
775+
for (ir.Supertype constraint in node.onClause) {
776776
interfaces.add(processSupertype(constraint));
777777
}
778778
// Set superclass to `Object`.

pkg/compiler/lib/src/kernel/element_map_impl.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ class KernelToElementMap implements IrToElementMap {
410410
//
411411
// so we need get the superclasses from the on-clause, A, B, and C,
412412
// through [superclassConstraints].
413-
for (ir.Supertype constraint in node.superclassConstraints()) {
413+
for (ir.Supertype constraint in node.onClause) {
414414
interfaces.add(processSupertype(constraint));
415415
}
416416
// Set superclass to `Object`.

pkg/compiler/lib/src/kernel/transformations/clone_mixin_methods_with_super.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ class _CloneMixinMethodsWithSuper {
6060
ensureExistingProcedureMaps();
6161
Procedure? existingGetter = existingNonSetters[field.name];
6262
Procedure? existingSetter = existingSetters[field.name];
63-
cls.addField(cloneVisitor.cloneField(
64-
field, null, existingGetter?.reference, existingSetter?.reference));
63+
Field clone = cloneVisitor.cloneField(
64+
field, null, existingGetter?.reference, existingSetter?.reference);
65+
cls.addField(clone);
66+
clone.transformerFlags = field.transformerFlags;
6567
if (existingGetter != null) {
6668
cls.procedures.remove(existingGetter);
6769
}
@@ -84,8 +86,10 @@ class _CloneMixinMethodsWithSuper {
8486
if (existingProcedure != null) {
8587
cls.procedures.remove(existingProcedure);
8688
}
87-
cls.addProcedure(cloneVisitor.cloneProcedure(
88-
procedure, existingProcedure?.reference));
89+
Procedure clone = cloneVisitor.cloneProcedure(
90+
procedure, existingProcedure?.reference);
91+
cls.addProcedure(clone);
92+
clone.transformerFlags = procedure.transformerFlags;
8993
continue;
9094
}
9195
}

pkg/compiler/lib/src/kernel/transformations/late_lowering.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,9 @@ class LateLowering {
537537
fileUri: fileUri, reference: field.getterReference)
538538
..fileOffset = fileOffset
539539
..isNonNullableByDefault = true;
540+
// The initializer is copied from [field] to [getter] so we copy the
541+
// transformer flags to reflect whether the getter contains super calls.
542+
getter.transformerFlags = field.transformerFlags;
540543
enclosingClass.addProcedure(getter);
541544

542545
VariableDeclaration setterValue = VariableDeclaration('value', type: type)

pkg/dev_compiler/lib/src/kernel/compiler.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,8 +1397,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
13971397
var savedClass = _classEmittingSignatures;
13981398
_classEmittingSignatures = c;
13991399

1400-
var interfaces = c.implementedTypes.toList()
1401-
..addAll(c.superclassConstraints());
1400+
var interfaces = c.implementedTypes.toList()..addAll(c.onClause);
14021401
if (interfaces.isNotEmpty) {
14031402
body.add(js.statement('#[#] = () => [#];', [
14041403
className,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ enum BenchmarkPhases {
176176
outline_installAllComponentProblems,
177177

178178
body_buildBodies,
179+
body_checkMixinSuperAccesses,
179180
body_finishSynthesizedParameters,
180181
body_finishDeferredLoadTearoffs,
181182
body_finishNoSuchMethodForwarders,

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,9 @@ class KernelTarget extends TargetImplementation {
617617
benchmarker?.enterPhase(BenchmarkPhases.body_buildBodies);
618618
await loader.buildBodies(loader.sourceLibraryBuilders);
619619

620+
benchmarker?.enterPhase(BenchmarkPhases.body_checkMixinSuperAccesses);
621+
loader.checkMixinSuperAccesses();
622+
620623
benchmarker?.enterPhase(BenchmarkPhases.body_finishSynthesizedParameters);
621624
finishSynthesizedParameters();
622625

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import 'package:_fe_analyzer_shared/src/messages/severity.dart' show Severity;
99
import 'package:kernel/ast.dart';
1010
import 'package:kernel/target/targets.dart';
1111

12-
import 'package:kernel/transformations/flags.dart' show TransformerFlag;
13-
1412
import 'package:kernel/type_environment.dart' show TypeEnvironment;
1513

1614
import 'package:kernel/verifier.dart'
@@ -170,7 +168,7 @@ class FastaVerifyingVisitor extends VerifyingVisitor {
170168
if (containingMember == null) {
171169
problem(node, 'Super call outside of any member');
172170
} else {
173-
if (containingMember.transformerFlags & TransformerFlag.superCalls == 0) {
171+
if (!containingMember.containsSuperCalls) {
174172
problem(
175173
node, 'Super call in a member lacking TransformerFlag.superCalls');
176174
}

pkg/front_end/lib/src/fasta/source/source_class_builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,7 @@ class SourceClassBuilder extends ClassBuilderImpl
955955
// the declaration's superclass constraints.
956956
InterfaceType supertype = cls.supertype!.asInterfaceType;
957957
Substitution substitution = Substitution.fromSupertype(cls.mixedInType!);
958-
for (Supertype constraint in cls.mixedInClass!.superclassConstraints()) {
958+
for (Supertype constraint in cls.mixedInClass!.onClause) {
959959
InterfaceType requiredInterface =
960960
substitution.substituteSupertype(constraint).asInterfaceType;
961961
InterfaceType? implementedInterface = hierarchy.getTypeAsInstanceOf(

pkg/front_end/lib/src/fasta/source/source_field_builder.dart

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,6 @@ class SourceFieldBuilder extends SourceMemberBuilderImpl
392392
ClassHierarchy classHierarchy,
393393
List<DelayedActionPerformer> delayedActionPerformers,
394394
List<DelayedDefaultValueCloner> delayedDefaultValueCloners) {
395-
_fieldEncoding.completeSignature(classHierarchy.coreTypes);
396-
397395
for (Annotatable annotatable in _fieldEncoding.annotatables) {
398396
MetadataBuilder.buildAnnotations(
399397
annotatable,
@@ -593,10 +591,6 @@ abstract class FieldEncoding {
593591
/// Returns a list of the setters created by this field encoding.
594592
List<ClassMember> getLocalSetters(SourceFieldBuilder fieldBuilder);
595593

596-
/// Ensures that the signatures all members created by this field encoding
597-
/// are fully typed.
598-
void completeSignature(CoreTypes coreTypes);
599-
600594
/// Returns `true` if this encoding is a late lowering.
601595
bool get isLateLowering;
602596
}
@@ -657,9 +651,6 @@ class RegularFieldEncoding implements FieldEncoding {
657651
_field.type = value;
658652
}
659653

660-
@override
661-
void completeSignature(CoreTypes coreTypes) {}
662-
663654
@override
664655
void createBodies(CoreTypes coreTypes, Expression? initializer) {
665656
if (initializer != null) {
@@ -899,11 +890,6 @@ abstract class AbstractLateFieldEncoding implements FieldEncoding {
899890
late_lowering.computeIsSetEncoding(_type!, _isSetStrategy);
900891
}
901892

902-
@override
903-
void completeSignature(CoreTypes coreTypes) {
904-
_lateIsSetField?.type = coreTypes.boolRawType(Nullability.nonNullable);
905-
}
906-
907893
@override
908894
void createBodies(CoreTypes coreTypes, Expression? initializer) {
909895
assert(_type != null, "Type has not been computed for field $name.");
@@ -924,6 +910,10 @@ abstract class AbstractLateFieldEncoding implements FieldEncoding {
924910
}
925911
_lateGetter.function.body = _createGetterBody(coreTypes, name, initializer)
926912
..parent = _lateGetter.function;
913+
// The initializer is copied from [_field] to [_lateGetter] so we copy the
914+
// transformer flags to reflect whether the getter contains super calls.
915+
_lateGetter.transformerFlags = _field.transformerFlags;
916+
927917
if (_lateSetter != null) {
928918
_lateSetter!.function.body = _createSetterBody(
929919
coreTypes, name, _lateSetter!.function.positionalParameters.first)
@@ -1099,7 +1089,9 @@ abstract class AbstractLateFieldEncoding implements FieldEncoding {
10991089
_lateIsSetField!
11001090
..isStatic = !isInstanceMember
11011091
..isStatic = _field.isStatic
1102-
..isExtensionMember = isExtensionMember;
1092+
..isExtensionMember = isExtensionMember
1093+
..type = libraryBuilder.loader
1094+
.createCoreType('bool', Nullability.nonNullable);
11031095
updatePrivateMemberName(_lateIsSetField!, libraryBuilder);
11041096
}
11051097
_lateGetter
@@ -1721,9 +1713,6 @@ class AbstractOrExternalFieldEncoding implements FieldEncoding {
17211713
}
17221714
}
17231715

1724-
@override
1725-
void completeSignature(CoreTypes coreTypes) {}
1726-
17271716
@override
17281717
void createBodies(CoreTypes coreTypes, Expression? initializer) {
17291718
//assert(initializer != null);

pkg/front_end/lib/src/fasta/source/source_library_builder.dart

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
13001300
.addAll(part.library.problemsAsJson!);
13011301
}
13021302
part.collectInferableTypes(_inferableTypes!);
1303+
part.takeMixinApplications(_mixinApplications!);
13031304
if (library != part.library) {
13041305
// Mark the part library as synthetic as it's not an actual library
13051306
// (anymore).
@@ -1863,12 +1864,12 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
18631864
if (declaration.declaresConstConstructor) {
18641865
modifiers |= declaresConstConstructorMask;
18651866
}
1866-
ClassBuilder classBuilder = new SourceClassBuilder(
1867+
SourceClassBuilder classBuilder = new SourceClassBuilder(
18671868
metadata,
18681869
modifiers,
18691870
className,
18701871
typeVariables,
1871-
applyMixins(supertype, mixins, startOffset, nameOffset, endOffset,
1872+
_applyMixins(supertype, mixins, startOffset, nameOffset, endOffset,
18721873
className, isMixinDeclaration,
18731874
typeVariables: typeVariables,
18741875
isMacro: false,
@@ -2137,7 +2138,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
21372138
getterReference: referenceFrom?.reference);
21382139
}
21392140

2140-
TypeBuilder? applyMixins(
2141+
TypeBuilder? _applyMixins(
21412142
TypeBuilder? supertype,
21422143
MixinApplicationBuilder? mixinApplications,
21432144
int startCharOffset,
@@ -2397,13 +2398,42 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
23972398
applicationTypeArguments, charOffset,
23982399
instanceTypeVariableAccess:
23992400
InstanceTypeVariableAccessState.Allowed);
2401+
registerMixinApplication(application, mixin);
24002402
}
24012403
return supertype;
24022404
} else {
24032405
return supertype;
24042406
}
24052407
}
24062408

2409+
Map<SourceClassBuilder, TypeBuilder>? _mixinApplications = {};
2410+
2411+
/// Registers that [mixinApplication] is a mixin application introduced by
2412+
/// the [mixedInType] in a with-clause.
2413+
///
2414+
/// This is used to check that super access in mixin declarations have a
2415+
/// concrete target.
2416+
void registerMixinApplication(
2417+
SourceClassBuilder mixinApplication, TypeBuilder mixedInType) {
2418+
assert(
2419+
_mixinApplications != null, "Late registration of mixin application.");
2420+
_mixinApplications![mixinApplication] = mixedInType;
2421+
}
2422+
2423+
void takeMixinApplications(
2424+
Map<SourceClassBuilder, TypeBuilder> mixinApplications) {
2425+
assert(_mixinApplications != null,
2426+
"Mixin applications have already been processed.");
2427+
mixinApplications.addAll(_mixinApplications!);
2428+
_mixinApplications = null;
2429+
Iterable<SourceLibraryBuilder>? patchLibraries = this.patchLibraries;
2430+
if (patchLibraries != null) {
2431+
for (SourceLibraryBuilder patchLibrary in patchLibraries) {
2432+
patchLibrary.takeMixinApplications(mixinApplications);
2433+
}
2434+
}
2435+
}
2436+
24072437
void addNamedMixinApplication(
24082438
List<MetadataBuilder>? metadata,
24092439
String name,
@@ -2420,7 +2450,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
24202450
// Nested declaration began in `OutlineBuilder.beginNamedMixinApplication`.
24212451
endNestedDeclaration(TypeParameterScopeKind.namedMixinApplication, name)
24222452
.resolveNamedTypes(typeVariables, this);
2423-
supertype = applyMixins(supertype, mixinApplication, startCharOffset,
2453+
supertype = _applyMixins(supertype, mixinApplication, startCharOffset,
24242454
charOffset, charEndOffset, name, false,
24252455
metadata: metadata,
24262456
name: name,
@@ -2876,7 +2906,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
28762906
metadata,
28772907
name,
28782908
typeVariables,
2879-
applyMixins(
2909+
_applyMixins(
28802910
loader.target.underscoreEnumType,
28812911
supertypeBuilder,
28822912
startCharOffset,

0 commit comments

Comments
 (0)