-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathscope_map_lookup.swift
127 lines (98 loc) · 2.43 KB
/
scope_map_lookup.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// XFAIL: *
// RUN: %target-typecheck-verify-swift -enable-astscope-lookup
// Name lookup in default arguments
// FIXME: Semantic analysis should not recommend 'x' or 'y' here, because they
// are not actually available.
func functionParamScopes(x: Int, y: Int = x) -> Int {
// expected-error@-1 {{cannot find 'x' in scope}}
// expected-note@-2 {{did you mean 'x'?}}
// expected-note@-2 {{did you mean 'y'?}}
return x + y
}
// Name lookup in instance methods.
class C1 {
var x = 0
var hashValue: Int {
return x
}
}
// Protocols involving 'Self'.
protocol P1 {
associatedtype A = Self
}
// Protocols involving associated types.
protocol AProtocol {
associatedtype e : e
// expected-error@-1 {{type 'Self.e' constrained to non-protocol, non-class type 'Self.e'}}
}
// Extensions.
protocol P2 {
}
extension P2 {
func getSelf() -> Self {
return self
}
}
#if false
// Lazy properties
class LazyProperties {
init() {
lazy var localvar = 42 // FIXME: should error {{lazy is only valid for members of a struct or class}} {{5-10=}}
localvar += 1
_ = localvar
}
var value: Int = 17
lazy var prop1: Int = value
lazy var prop2: Int = { value + 1 }()
lazy var prop3: Int = { [weak self] in self.value + 1 }()
lazy var prop4: Int = self.value
lazy var prop5: Int = { self.value + 1 }()
}
#endif
// Protocol extensions.
// Extending via a superclass constraint.
class Superclass {
func foo() { }
static func bar() { }
typealias Foo = Int
}
protocol PConstrained4 { }
extension PConstrained4 where Self : Superclass {
func testFoo() -> Foo {
foo()
self.foo()
return Foo(5)
}
static func testBar() {
bar()
self.bar()
}
}
// Local computed properties.
func localComputedProperties() {
var localProperty: Int {
get {
return localProperty // expected-warning{{attempting to access 'localProperty' within its own getter}}
}
set {
_ = newValue
print(localProperty)
}
}
{ print(localProperty) }()
}
// Top-level code.
func topLevel() { }
topLevel()
let c1opt: C1? = C1()
guard let c1 = c1opt else { }
protocol Fooable {
associatedtype Foo
var foo: Foo { get }
}
// The extension below once caused infinite recursion.
struct S<T> // expected-error{{expected '{' in struct}}
extension S // expected-error{{expected '{' in extension}}
let a = b ; let b = a
// expected-note@-1 {{'a' declared here}}
// expected-error@-2 {{ambiguous use of 'a'}}