Skip to content

Commit 719c8ff

Browse files
authored
Merge pull request swiftlang#9046 from greglutz/SR-4683
Fix for SR-4683
2 parents e2fdea9 + ed48336 commit 719c8ff

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,14 +1695,19 @@ void ASTMangler::appendDeclType(const ValueDecl *decl, bool isFunctionMangling)
16951695
requirements, requirementsBuf);
16961696

16971697
if (AnyFunctionType *FuncTy = type->getAs<AnyFunctionType>()) {
1698-
bool forceSingleParam = false;
1698+
1699+
const ParameterList *Params = nullptr;
16991700
if (const auto *FDecl = dyn_cast<AbstractFunctionDecl>(decl)) {
17001701
unsigned PListIdx = isMethodDecl(decl) ? 1 : 0;
17011702
if (PListIdx < FDecl->getNumParameterLists()) {
1702-
const ParameterList *Params = FDecl->getParameterList(PListIdx);
1703-
forceSingleParam = (Params->size() == 1);
1703+
Params = FDecl->getParameterList(PListIdx);
17041704
}
1705+
} else if (const auto *SDecl = dyn_cast<SubscriptDecl>(decl)) {
1706+
Params = SDecl->getIndices();
17051707
}
1708+
bool forceSingleParam = Params && (Params->size() == 1);
1709+
1710+
17061711
if (isFunctionMangling) {
17071712
appendFunctionSignature(FuncTy, forceSingleParam);
17081713
} else {

test/SILGen/arguments_as_tuple_overloads.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// RUN: %target-swift-frontend -parse-as-library -module-name=test -emit-silgen -primary-file %s | %FileCheck %s
22

3-
// Check if we mangle the following constructors and functions correctly.
3+
// Check if we mangle the following constructors, functions, and
4+
// subscripts correctly.
45

56
public struct Pair {
67
// CHECK: sil @_T04test4PairVACSi_SitcfC :
@@ -18,6 +19,16 @@ public struct Pair {
1819
// CHECK: sil @_T04test4PairVAAySi_Sit_tF :
1920
public func test(_ t: (Int, Int)) {
2021
}
22+
23+
// CHECK: sil @_T04test4PairV9subscriptS2i_Sitcfg :
24+
public subscript(_:Int, _:Int) -> Int {
25+
get { return 0 }
26+
}
27+
28+
// CHECK: sil @_T04test4PairV9subscriptS2i_Sit_tcfg :
29+
public subscript(_:(Int, Int)) -> Int {
30+
get { return 0 }
31+
}
2132
}
2233

2334
// CHECK: sil @_T04testAAySi_SitF :

test/SILGen/constrained_extensions.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extension Array where Element == Int {
4848
return e!
4949
}
5050

51-
// CHECK-LABEL: sil @_T0Sa22constrained_extensionsSiRszlE9subscriptSiycfg : $@convention(method) (@guaranteed Array<Int>) -> Int
51+
// CHECK-LABEL: sil @_T0Sa22constrained_extensionsSiRszlE9subscriptSiyt_tcfg : $@convention(method) (@guaranteed Array<Int>) -> Int
5252
public subscript(i: ()) -> Element {
5353
return self[0]
5454
}
@@ -119,7 +119,7 @@ extension Dictionary where Key == Int {
119119
return Dictionary(x: ()).instanceMethod()
120120
}
121121

122-
// CHECK-LABEL: sil @_T0s10DictionaryV22constrained_extensionsSiRszr0_lE9subscriptq_ycfg : $@convention(method) <Key, Value where Key == Int> (@guaranteed Dictionary<Int, Value>) -> @out Value
122+
// CHECK-LABEL: sil @_T0s10DictionaryV22constrained_extensionsSiRszr0_lE9subscriptq_yt_tcfg : $@convention(method) <Key, Value where Key == Int> (@guaranteed Dictionary<Int, Value>) -> @out Value
123123
public subscript(i: ()) -> Value {
124124
return self[0]!
125125
}
@@ -153,10 +153,10 @@ extension GenericClass where Y == () {
153153
set {}
154154
}
155155

156-
// CHECK-LABEL: sil @_T022constrained_extensions12GenericClassCAAytRs_r0_lE9subscriptxycfg : $@convention(method) <X, Y where Y == ()> (@guaranteed GenericClass<X, ()>) -> @out X
157-
// CHECK-LABEL: sil @_T022constrained_extensions12GenericClassCAAytRs_r0_lE9subscriptxycfs : $@convention(method) <X, Y where Y == ()> (@in X, @guaranteed GenericClass<X, ()>) -> ()
158-
// CHECK-LABEL: sil [transparent] [serialized] @_T022constrained_extensions12GenericClassCAAytRs_r0_lE9subscriptxycfmytfU_ : $@convention(method) <X, Y where Y == ()> (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout GenericClass<X, ()>, @thick GenericClass<X, ()>.Type) -> ()
159-
// CHECK-LABEL: sil [transparent] [serialized] @_T022constrained_extensions12GenericClassCAAytRs_r0_lE9subscriptxycfm : $@convention(method) <X, Y where Y == ()> (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @guaranteed GenericClass<X, ()>) -> (Builtin.RawPointer, Optional<Builtin.RawPointer>)
156+
// CHECK-LABEL: sil @_T022constrained_extensions12GenericClassCAAytRs_r0_lE9subscriptxyt_tcfg : $@convention(method) <X, Y where Y == ()> (@guaranteed GenericClass<X, ()>) -> @out X
157+
// CHECK-LABEL: sil @_T022constrained_extensions12GenericClassCAAytRs_r0_lE9subscriptxyt_tcfs : $@convention(method) <X, Y where Y == ()> (@in X, @guaranteed GenericClass<X, ()>) -> ()
158+
// CHECK-LABEL: sil [transparent] [serialized] @_T022constrained_extensions12GenericClassCAAytRs_r0_lE9subscriptxyt_tcfmytfU_ : $@convention(method) <X, Y where Y == ()> (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @inout GenericClass<X, ()>, @thick GenericClass<X, ()>.Type) -> ()
159+
// CHECK-LABEL: sil [transparent] [serialized] @_T022constrained_extensions12GenericClassCAAytRs_r0_lE9subscriptxyt_tcfm : $@convention(method) <X, Y where Y == ()> (Builtin.RawPointer, @inout Builtin.UnsafeValueBuffer, @guaranteed GenericClass<X, ()>) -> (Builtin.RawPointer, Optional<Builtin.RawPointer>)
160160
public subscript(_: Y) -> X {
161161
get { while true {} }
162162
set {}

0 commit comments

Comments
 (0)