Skip to content

Commit e3b7d5d

Browse files
authored
Merge pull request #33620 from CodaFi/a-look-alike
2 parents 76da9a0 + c9b3164 commit e3b7d5d

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

lib/Sema/TypeCheckStmt.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,9 +1764,9 @@ static bool checkSuperInit(ConstructorDecl *fromCtor,
17641764
NLOptions subOptions = NL_QualifiedDefault | NL_KnownNonCascadingDependency;
17651765

17661766
SmallVector<ValueDecl *, 4> lookupResults;
1767-
dc->lookupQualified(superclassDecl,
1768-
DeclNameRef::createConstructor(),
1769-
subOptions, lookupResults);
1767+
fromCtor->lookupQualified(superclassDecl,
1768+
DeclNameRef::createConstructor(),
1769+
subOptions, lookupResults);
17701770

17711771
for (auto decl : lookupResults) {
17721772
auto superclassCtor = dyn_cast<ConstructorDecl>(decl);

test/SILOptimizer/Inputs/definite_init_cross_module/OtherModule.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,14 @@ public struct Empty {
4141
public struct GenericEmpty<T> {
4242
public init() {}
4343
}
44+
45+
open class VisibleNoArgsDesignatedInit {
46+
var x: Float
47+
public init() { x = 0.0 }
48+
49+
// Add some designated inits the subclass cannot see.
50+
private init(x: Float) { self.x = x }
51+
fileprivate init(y: Float) { self.x = y }
52+
internal init(z: Float) { self.x = z }
53+
}
54+

test/SILOptimizer/definite_init_cross_module.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,27 @@ extension GenericEmpty {
254254
init(xx: Double) {
255255
} // expected-error {{'self.init' isn't called on all paths before returning from initializer}}
256256
}
257+
258+
class AcceptsVisibleNoArgsDesignatedInit: VisibleNoArgsDesignatedInit {
259+
var y: Float
260+
init(y: Float) {
261+
self.y = y
262+
// no error
263+
}
264+
}
265+
266+
open class InModuleVisibleNoArgsDesignatedInit {
267+
var x: Float
268+
public init() { x = 0.0 }
269+
270+
// Add a designated init the subclass cannot see.
271+
private init(x: Float) { self.x = x }
272+
}
273+
274+
class AcceptsInModuleVisibleNoArgsDesignatedInit: InModuleVisibleNoArgsDesignatedInit {
275+
var y: Float
276+
init(y: Float) {
277+
self.y = y
278+
// no error
279+
}
280+
}

0 commit comments

Comments
 (0)