Skip to content

Commit ae1f250

Browse files
committed
[TBDGen] Ensure that we emit default argument generators for subscripts.
Fixes rdar://89258902.
1 parent 70fa3df commit ae1f250

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

lib/TBDGen/TBDGen.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,11 @@ void TBDGenVisitor::visitVarDecl(VarDecl *VD) {
848848
visitAbstractStorageDecl(VD);
849849
}
850850

851+
void TBDGenVisitor::visitSubscriptDecl(SubscriptDecl *SD) {
852+
visitDefaultArguments(SD, SD->getIndices());
853+
visitAbstractStorageDecl(SD);
854+
}
855+
851856
void TBDGenVisitor::visitNominalTypeDecl(NominalTypeDecl *NTD) {
852857
auto declaredType = NTD->getDeclaredType()->getCanonicalType();
853858

lib/TBDGen/TBDGenVisitor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ class TBDGenVisitor : public ASTVisitor<TBDGenVisitor> {
214214

215215
void visitVarDecl(VarDecl *VD);
216216

217+
void visitSubscriptDecl(SubscriptDecl *SD);
218+
217219
void visitEnumDecl(EnumDecl *ED);
218220

219221
void visitEnumElementDecl(EnumElementDecl *EED);

test/TBD/subscript.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// REQUIRES: VENDOR=apple
2+
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all %s
3+
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all %s -enable-testing
4+
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all %s -O
5+
// RUN: %target-swift-frontend -emit-ir -o/dev/null -parse-as-library -module-name test -validate-tbd-against-ir=all %s -enable-testing -O
6+
7+
// RUN: %empty-directory(%t)
8+
// RUN: %target-swift-frontend -typecheck -parse-as-library -module-name test %s -emit-tbd -emit-tbd-path %t/typecheck.tbd
9+
// RUN: %target-swift-frontend -emit-ir -parse-as-library -module-name test %s -emit-tbd -emit-tbd-path %t/emit-ir.tbd
10+
// RUN: diff -u %t/typecheck.tbd %t/emit-ir.tbd
11+
12+
public protocol DefaultInit {
13+
init()
14+
}
15+
16+
@available(macOS 10.15, *)
17+
struct X {
18+
subscript<T: DefaultInit>(_ value: Int = 0, other: T = T()) -> Int { value + 1 }
19+
20+
static subscript<T>(_ value: String = "hello", other: T) -> String {
21+
get { value }
22+
set { }
23+
}
24+
}
25+

0 commit comments

Comments
 (0)