Skip to content

Commit b5074d3

Browse files
committed
Add test cases for special subscript name
1 parent b9c2a69 commit b5074d3

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

test/SILGen/vtables.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,15 @@ class DerivedWithoutDefaults : BaseWithDefaults {
169169

170170
// CHECK-LABEL: sil_vtable DerivedWithoutDefaults {
171171
// CHECK: #BaseWithDefaults.a!1: {{.*}} : _T07vtables22DerivedWithoutDefaultsC1a{{[_0-9a-zA-Z]*}}F
172+
173+
174+
175+
// Escape identifiers that represent special names
176+
177+
class SubscriptAsFunction {
178+
func `subscript`() {}
179+
}
180+
181+
// CHECK-LABEL: sil_vtable SubscriptAsFunction {
182+
// CHECK-NOT: #SubscriptAsFunction.subscript
183+
// CHECK: #SubscriptAsFunction.`subscript`!1

test/Sema/subscripting.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-run-simple-swift | %FileCheck %s
2+
3+
// Check that subscripts and functions named subscript can exist side-by-side
4+
struct Foo {
5+
subscript() -> String {
6+
return "subscript"
7+
}
8+
9+
func `subscript`() -> String {
10+
return "func"
11+
}
12+
}
13+
14+
let f = Foo()
15+
print(f[]) // CHECK: subscript
16+
print(f.subscript()) // CHECK: func

test/decl/protocol/conforms/fixit_stub.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,10 @@ protocol ProtocolRequiresInit3 {
145145

146146
struct Adopter14 {} // expected-note{{candidate}}
147147
extension Adopter14 : ProtocolRequiresInit3 {} //expected-error {{type 'Adopter14' does not conform to protocol 'ProtocolRequiresInit3'}}
148+
149+
protocol ProtocolHasSubscriptFunction {
150+
func `subscript`() // expected-note{{protocol requires function 'subscript()' with type '() -> ()'; do you want to add a stub?}} {{74-74=\n func `subscript`() {\n <#code#>\n \}\n}}
151+
}
152+
class ProtocolHasSubscriptFunctionAdopter: ProtocolHasSubscriptFunction { // expected-error{{type 'ProtocolHasSubscriptFunctionAdopter' does not conform to protocol 'ProtocolHasSubscriptFunction'}}
153+
154+
}

test/decl/subscript/subscripting.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,12 @@ struct S4 {
310310
}
311311
}
312312
}
313+
314+
// SR-2575
315+
struct SR2575 {
316+
subscript() -> Int {
317+
return 1
318+
}
319+
}
320+
321+
SR2575().subscript() // expected-error{{type 'SR2575' has no member 'subscript'}}

0 commit comments

Comments
 (0)