diff --git a/lib/Sema/TypeCheckStmt.cpp b/lib/Sema/TypeCheckStmt.cpp index eb3495302f68e..7ad3b65597a4f 100644 --- a/lib/Sema/TypeCheckStmt.cpp +++ b/lib/Sema/TypeCheckStmt.cpp @@ -2163,11 +2163,15 @@ static Expr* constructCallToSuperInit(ConstructorDecl *ctor, /// \returns true if an error occurred. static bool checkSuperInit(ConstructorDecl *fromCtor, ApplyExpr *apply, bool implicitlyGenerated) { + auto Callee = apply->getSemanticFn(); + if (auto dotCall = dyn_cast(Callee)) + Callee = dotCall->getSemanticFn(); + // Make sure we are referring to a designated initializer. - auto otherCtorRef = dyn_cast( - apply->getSemanticFn()); - if (!otherCtorRef) + auto otherCtorRef = dyn_cast(Callee); + if (!otherCtorRef) { return false; + } auto ctor = otherCtorRef->getDecl(); if (!ctor->isDesignatedInit()) { diff --git a/test/decl/func/complete_object_init.swift b/test/decl/func/complete_object_init.swift index 7028f89416b36..6059dbc55f45d 100644 --- a/test/decl/func/complete_object_init.swift +++ b/test/decl/func/complete_object_init.swift @@ -4,7 +4,7 @@ // Declaration of complete object initializers and basic semantic checking // --------------------------------------------------------------------------- class A { - convenience init(int i: Int) { // expected-note{{convenience initializer is declared here}} + convenience init(int i: Int) { // expected-note 5 {{convenience initializer is declared here}} self.init(double: Double(i)) } @@ -39,6 +39,38 @@ class DerivesA : A { } } +// Fixing https://github.com/swiftlang/swift/issues/80311 +class DerivesAWithLet : A { + let str: String + init(int i: Int) { + str = "foo" + super.init(int: i) // expected-error{{must call a designated initializer of the superclass 'A'}} + } +} + +class DerivesAWithVar : A { + var str: String + init(int i: Int) { + str = "foo" + super.init(int: i) // expected-error{{must call a designated initializer of the superclass 'A'}} + } +} + +class DerivesAWithDefaultLet : A { + let str: String = "foo" + init(int i: Int) { + super.init(int: i) // expected-error{{must call a designated initializer of the superclass 'A'}} + } +} + +class DerivesAWithDefaultVar : A { + var str: String = "foo" + init(int i: Int) { + super.init(int: i) // expected-error{{must call a designated initializer of the superclass 'A'}} + } +} + + struct S { convenience init(int i: Int) { // expected-error{{initializers in structs are not marked with 'convenience'}} self.init(double: Double(i))