File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -357,6 +357,16 @@ diagnoseInvalidDynamicConstructorReferences(ConstraintSystem &cs,
357
357
return cs.getType (expr);
358
358
});
359
359
360
+ // 'super.' is always OK
361
+ if (isa<SuperRefExpr>(base))
362
+ return true ;
363
+
364
+ // 'self.' reference with concrete type is OK
365
+ if (isa<DeclRefExpr>(base) &&
366
+ cast<DeclRefExpr>(base)->getDecl ()->getBaseName () == tc.Context .Id_self &&
367
+ !baseTy->is <ArchetypeType>())
368
+ return true ;
369
+
360
370
// FIXME: The "hasClangNode" check here is a complete hack.
361
371
if (isNonFinalClass (instanceTy) &&
362
372
!isStaticallyDerived &&
@@ -2535,6 +2545,13 @@ namespace {
2535
2545
ConstructorDecl *ctor,
2536
2546
FunctionRefKind functionRefKind,
2537
2547
Type openedType) {
2548
+
2549
+ // If the member is a constructor, verify that it can be legally
2550
+ // referenced from this base.
2551
+ if (!diagnoseInvalidDynamicConstructorReferences (cs, base, nameLoc,
2552
+ ctor, SuppressDiagnostics))
2553
+ return nullptr ;
2554
+
2538
2555
// If the subexpression is a metatype, build a direct reference to the
2539
2556
// constructor.
2540
2557
if (cs.getType (base)->is <AnyMetatypeType>()) {
Original file line number Diff line number Diff line change @@ -267,6 +267,22 @@ extension ExtendedProtocol where Self : DerivedWithAlias {
267
267
func f4( x: NestedNominal ) { }
268
268
}
269
269
270
+ // rdar://problem/21991470 & https://bugs.swift.org/browse/SR-5022
271
+ class NonPolymorphicInit {
272
+ init ( ) { } // expected-note {{selected non-required initializer 'init()'}}
273
+ }
274
+
275
+ protocol EmptyProtocol { }
276
+
277
+ // The diagnostic is not very accurate, but at least we reject this.
278
+
279
+ extension EmptyProtocol where Self : NonPolymorphicInit {
280
+ init ( string: String ) {
281
+ self . init ( )
282
+ // expected-error@-1 {{constructing an object of class type 'Self' with a metatype value must use a 'required' initializer}}
283
+ }
284
+ }
285
+
270
286
// ----------------------------------------------------------------------------
271
287
// Using protocol extensions to satisfy requirements
272
288
// ----------------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments