Skip to content

Commit e765d9d

Browse files
committed
Sema: Check reference to implicitly-generated super.init() call from inlinable context
Fixes <https://bugs.swift.org/browse/SR-10940>.
1 parent 1a57f5e commit e765d9d

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

Diff for: lib/Sema/TypeCheckStmt.cpp

+13-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//===----------------------------------------------------------------------===//
1616

1717
#include "TypeChecker.h"
18+
#include "TypeCheckAvailability.h"
1819
#include "TypeCheckType.h"
1920
#include "MiscDiagnostics.h"
2021
#include "ConstraintSystem.h"
@@ -2050,8 +2051,19 @@ static bool checkSuperInit(TypeChecker &tc, ConstructorDecl *fromCtor,
20502051
// super.init() call.
20512052
return true;
20522053
}
2054+
2055+
// Make sure we can reference the designated initializer correctly.
2056+
if (fromCtor->getResilienceExpansion() == ResilienceExpansion::Minimal) {
2057+
TypeChecker::FragileFunctionKind fragileKind;
2058+
bool treatUsableFromInlineAsPublic;
2059+
std::tie(fragileKind, treatUsableFromInlineAsPublic) =
2060+
tc.getFragileFunctionKind(fromCtor);
2061+
tc.diagnoseInlinableDeclRef(
2062+
fromCtor->getLoc(), ctor, fromCtor, fragileKind,
2063+
treatUsableFromInlineAsPublic);
2064+
}
20532065
}
2054-
2066+
20552067
return false;
20562068
}
20572069

Diff for: test/attr/attr_inlinable.swift

+32
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ enum InternalEnum {
167167
_ = VersionedEnum.persimmon
168168
}
169169

170+
170171
// Inherited initializers - <rdar://problem/34398148>
171172
@usableFromInline
172173
@_fixed_layout
@@ -188,6 +189,7 @@ class Derived : Middle {
188189
}
189190
}
190191

192+
191193
// More inherited initializers
192194
@_fixed_layout
193195
public class Base2 {
@@ -208,6 +210,36 @@ class Derived2 : Middle2 {
208210
}
209211
}
210212

213+
214+
// Even more inherited initializers - https://bugs.swift.org/browse/SR-10940
215+
@_fixed_layout
216+
public class Base3 {}
217+
// expected-note@-1 {{initializer 'init()' is not '@usableFromInline' or public}}
218+
219+
@_fixed_layout
220+
public class Derived3 : Base3 {
221+
@inlinable
222+
public init(_: Int) {}
223+
// expected-error@-1 {{initializer 'init()' is internal and cannot be referenced from an '@inlinable' function}}
224+
}
225+
226+
@_fixed_layout
227+
public class Base4 {}
228+
229+
@_fixed_layout
230+
@usableFromInline
231+
class Middle4 : Base4 {}
232+
// expected-note@-1 {{initializer 'init()' is not '@usableFromInline' or public}}
233+
234+
@_fixed_layout
235+
@usableFromInline
236+
class Derived4 : Middle4 {
237+
@inlinable
238+
public init(_: Int) {}
239+
// expected-error@-1 {{initializer 'init()' is internal and cannot be referenced from an '@inlinable' function}}
240+
}
241+
242+
211243
// Stored property initializer expressions.
212244
//
213245
// Note the behavior here does not depend on the state of the -enable-library-evolution

0 commit comments

Comments
 (0)