Skip to content

Commit ad03aa9

Browse files
[Sema] Check for availability of result type of implicit literal initializer
1 parent 66f6769 commit ad03aa9

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,13 +3256,15 @@ class ExprAvailabilityWalker : public ASTWalker {
32563256
}
32573257

32583258
if (auto *LE = dyn_cast<LiteralExpr>(E)) {
3259-
auto Range = LE->getSourceRange();
3260-
if (auto *RLE = dyn_cast<RegexLiteralExpr>(LE)) {
3261-
// Regex literals require both the Regex<Output> type to be available,
3262-
// as well as the initializer that is implicitly called.
3263-
diagnoseDeclRefAvailability(Context.getRegexDecl(), Range);
3259+
if (auto literalType = LE->getType()) {
3260+
// Check availability of the type produced by implicit literal
3261+
// initializer.
3262+
if (auto *nominalDecl = literalType->getAnyNominal()) {
3263+
diagnoseDeclAvailability(nominalDecl, LE->getSourceRange(),
3264+
/*call=*/nullptr, Where);
3265+
}
32643266
}
3265-
diagnoseDeclRefAvailability(LE->getInitializer(), Range);
3267+
diagnoseDeclRefAvailability(LE->getInitializer(), LE->getSourceRange());
32663268
}
32673269

32683270
if (auto *CE = dyn_cast<CollectionExpr>(E)) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 5
2+
3+
// https://github.com/apple/swift/issues/61890
4+
5+
@available(*, unavailable)
6+
struct S: ExpressibleByStringLiteral { // expected-note{{'S' has been explicitly marked unavailable here}}
7+
init(stringLiteral value: String) {}
8+
}
9+
@available(*, unavailable)
10+
typealias StringLiteralType = S
11+
12+
let i = "" // expected-error{{'S' is unavailable}}
13+
14+
@available(*, unavailable)
15+
struct S1<T>: ExpressibleByIntegerLiteral { // expected-note{{'S1' has been explicitly marked unavailable here}}
16+
init(integerLiteral value: Int) {}
17+
}
18+
@available(*, unavailable)
19+
typealias IntegerLiteralType = S1<Int>
20+
21+
let a = 0 // expected-error{{'S1' is unavailable}}

0 commit comments

Comments
 (0)