Skip to content

Commit a93f8e6

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 b2758ca commit a93f8e6

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

lib/Sema/TypeCheckStmt.cpp

Lines changed: 13 additions & 1 deletion
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"
@@ -2074,8 +2075,19 @@ static bool checkSuperInit(TypeChecker &tc, ConstructorDecl *fromCtor,
20742075
// super.init() call.
20752076
return true;
20762077
}
2078+
2079+
// Make sure we can reference the designated initializer correctly.
2080+
if (fromCtor->getResilienceExpansion() == ResilienceExpansion::Minimal) {
2081+
TypeChecker::FragileFunctionKind fragileKind;
2082+
bool treatUsableFromInlineAsPublic;
2083+
std::tie(fragileKind, treatUsableFromInlineAsPublic) =
2084+
tc.getFragileFunctionKind(fromCtor);
2085+
tc.diagnoseInlinableDeclRef(
2086+
fromCtor->getLoc(), ctor, fromCtor, fragileKind,
2087+
treatUsableFromInlineAsPublic);
2088+
}
20772089
}
2078-
2090+
20792091
return false;
20802092
}
20812093

test/attr/attr_inlinable.swift

Lines changed: 32 additions & 0 deletions
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)