Skip to content

Commit 4aa2847

Browse files
Fixed some tests
Remaining failures: DebugInfo/guard-let-scope4.swift expr/closure/closures.swift SILGen/capture-transitive.swift SILGen/dynamic_self.swift SILGen/unowned-class-bound-generic-parameter.swift
1 parent 3e0de86 commit 4aa2847

File tree

7 files changed

+39
-35
lines changed

7 files changed

+39
-35
lines changed

test/Parse/invalid.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ prefix func %<T>(x: T) -> T { return x } // No error expected - the < is conside
119119

120120
struct Weak<T: class> { // expected-error {{'class' constraint can only appear on protocol declarations}}
121121
// expected-note@-1 {{did you mean to write an 'AnyObject' constraint?}} {{16-21=AnyObject}}
122-
weak let value: T // expected-error {{'weak' must be a mutable variable, because it may change at runtime}} expected-error {{'weak' variable should have optional type 'T?'}} expected-error {{'weak' must not be applied to non-class-bound 'T'; consider adding a protocol conformance that has a class bound}}
122+
weak let value: T // expected-error {{'weak' variable should have optional type 'T?'}} expected-error {{'weak' must not be applied to non-class-bound 'T'; consider adding a protocol conformance that has a class bound}}
123123
}
124124

125125
let x: () = ()

test/SILGen/capture_order.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public func captureBeforeDefWeakVar(obj: AnyObject) -> () -> AnyObject? {
2828
return weakObj // expected-note {{captured here}}
2929
}
3030
let closure = getter
31-
weak var weakObj: AnyObject? = obj // expected-note{{captured value declared here}}
31+
weak let weakObj: AnyObject? = obj // expected-note{{captured value declared here}}
3232
return closure
3333
}
3434

@@ -125,7 +125,7 @@ class С_47389 {
125125
let bar = { [weak self] in
126126
// expected-error@-1 {{closure captures 'bar' before it is declared}}
127127
// expected-note@-2 {{captured value declared here}}
128-
// expected-warning@-3 {{variable 'self' was written to, but never read}}
128+
// expected-warning@-3 {{capture 'self' was never used}}
129129
bar2()
130130
}
131131
func bar2() {

test/SILOptimizer/definite_init_diagnostics.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,15 @@ func test2() {
103103

104104

105105
// Weak
106+
// expected-warning @+1 {{variable 'w1' was never mutated; consider changing to 'let' constant}} {{8-11=let}}
106107
weak var w1 : SomeClass?
107108
_ = w1 // ok: default-initialized
108109

109110
// Note: with -enable-copy-propagation, we also expect: {{weak reference will always be nil because the referenced object is deallocated here}}
110111
// expected-warning@+3 {{instance will be immediately deallocated because variable 'w2' is 'weak'}}
111112
// expected-note@+2 {{a strong reference is required to prevent the instance from being deallocated}}
112113
// expected-note@+1 {{'w2' declared here}}
113-
weak var w2 = SomeClass()
114+
weak let w2 = SomeClass()
114115
_ = w2 // ok
115116

116117

test/Sema/diag_unowned_immediate_deallocation.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ func testUnownedVariableBindingDiag() throws {
271271
}
272272

273273
func testMultipleBindingDiag() {
274-
weak var c1 = C(), c2: C? = C(), c3: C? = D()
274+
weak let c1 = C(), c2: C? = C(), c3: C? = D()
275275
// expected-warning@-1 {{instance will be immediately deallocated because variable 'c1' is 'weak'}}
276276
// expected-note@-2 {{a strong reference is required to prevent the instance from being deallocated}}
277277
// expected-note@-3 {{'c1' declared here}}
@@ -297,7 +297,7 @@ func testMultipleBindingDiag() {
297297
}
298298

299299
func testTupleAndParenBinding() throws {
300-
weak var ((c1), c2, c3): (C?, C?, C?) = (C() as C, (D()), try D(throwing: ()))
300+
weak let ((c1), c2, c3): (C?, C?, C?) = (C() as C, (D()), try D(throwing: ()))
301301
// expected-warning@-1 {{instance will be immediately deallocated because variable 'c1' is 'weak'}}
302302
// expected-note@-2 {{a strong reference is required to prevent the instance from being deallocated}}
303303
// expected-note@-3 {{'c1' declared here}}
@@ -323,11 +323,11 @@ func testTupleAndParenBinding() throws {
323323
}
324324

325325
func testInitializationThroughClassArchetypeDiag<T : ClassProtocol>(_ t: T, _ p: ClassProtocol) throws {
326-
weak var t1: T? = T() // expected-warning {{instance will be immediately deallocated because variable 't1' is 'weak'}}
326+
weak let t1: T? = T() // expected-warning {{instance will be immediately deallocated because variable 't1' is 'weak'}}
327327
// expected-note@-1 {{a strong reference is required to prevent the instance from being deallocated}}
328328
// expected-note@-2 {{'t1' declared here}}
329329

330-
weak var t2: ClassProtocol? = T(failable: ()) // expected-warning {{instance will be immediately deallocated because variable 't2' is 'weak'}}
330+
weak let t2: ClassProtocol? = T(failable: ()) // expected-warning {{instance will be immediately deallocated because variable 't2' is 'weak'}}
331331
// expected-note@-1 {{a strong reference is required to prevent the instance from being deallocated}}
332332
// expected-note@-2 {{'t2' declared here}}
333333

@@ -342,7 +342,7 @@ func testInitializationThroughClassArchetypeDiag<T : ClassProtocol>(_ t: T, _ p:
342342
let optionalTType: T.Type? = T.self
343343
let optionalPType: ClassProtocol.Type? = type(of: p)
344344

345-
weak var t5 = optionalTType?.init(failable: ()) // expected-warning {{instance will be immediately deallocated because variable 't5' is 'weak'}}
345+
weak let t5 = optionalTType?.init(failable: ()) // expected-warning {{instance will be immediately deallocated because variable 't5' is 'weak'}}
346346
// expected-note@-1 {{a strong reference is required to prevent the instance from being deallocated}}
347347
// expected-note@-2 {{'t5' declared here}}
348348

@@ -404,12 +404,12 @@ class C1 {
404404
}
405405

406406
func testInitializationThroughMetaclassDiag(_ t: C.Type) {
407-
weak var c1: C? = t.init() // expected-warning {{instance will be immediately deallocated because variable 'c1' is 'weak'}}
407+
weak let c1: C? = t.init() // expected-warning {{instance will be immediately deallocated because variable 'c1' is 'weak'}}
408408
// expected-note@-1 {{a strong reference is required to prevent the instance from being deallocated}}
409409
// expected-note@-2 {{'c1' declared here}}
410410

411411
let optionalCType: C.Type? = t
412-
weak var c2 = optionalCType?.init(failable: ()) // expected-warning {{instance will be immediately deallocated because variable 'c2' is 'weak'}}
412+
weak let c2 = optionalCType?.init(failable: ()) // expected-warning {{instance will be immediately deallocated because variable 'c2' is 'weak'}}
413413
// expected-note@-1 {{a strong reference is required to prevent the instance from being deallocated}}
414414
// expected-note@-2 {{'c2' declared here}}
415415

@@ -439,7 +439,7 @@ func testInitializationThroughTupleElementDiag() {
439439
class E<T> {}
440440

441441
func testGenericWeakClassDiag() {
442-
weak var e = E<String>()
442+
weak let e = E<String>()
443443
// expected-warning@-1 {{instance will be immediately deallocated because variable 'e' is 'weak'}}
444444
// expected-note@-2 {{a strong reference is required to prevent the instance from being deallocated}}
445445
// expected-note@-3 {{'e' declared here}}
@@ -465,7 +465,7 @@ extension Optional {
465465
}
466466

467467
func testDontDiagnoseOnUnrelatedInitializer() {
468-
weak var c = C?(dontDiagnoseOnThis: ())
468+
weak let c = C?(dontDiagnoseOnThis: ())
469469
unowned let c1 = C?(dontDiagnoseOnThis: ())!
470470
_ = c; _ = c1
471471
}
@@ -476,8 +476,8 @@ class F {
476476
}
477477

478478
func testDontDiagnoseThroughMembers() {
479-
weak var c1 = F().c
480-
weak var c2 = F().makeC()
479+
weak let c1 = F().c
480+
weak let c2 = F().makeC()
481481
_ = c1; _ = c2
482482
}
483483

@@ -488,7 +488,7 @@ func testDontDiagnoseOnStrongVariable() {
488488
}
489489

490490
func testDontDiagnoseThroughImmediatelyEvaluatedClosure() {
491-
weak var c1 = { C() }()
491+
weak let c1 = { C() }()
492492
unowned let c2 = { C() }()
493493
_ = c1; _ = c2
494494
}

test/decl/var/properties.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ var x15: Int {
114114
// For the purpose of this test we need to use an attribute that cannot be
115115
// applied to the getter.
116116
weak
117-
var foo: SomeClass? = SomeClass() // expected-warning {{variable 'foo' was written to, but never read}}
117+
var foo: SomeClass? = SomeClass() // expected-warning {{variable 'foo' was never used; consider replacing with '_' or removing it}}
118118
// expected-warning@-1 {{instance will be immediately deallocated because variable 'foo' is 'weak'}}
119119
// expected-note@-2 {{a strong reference is required to prevent the instance from being deallocated}}
120120
// expected-note@-3 {{'foo' declared here}}

test/decl/var/variables.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ var shouldWarnWithoutSugar = (arrayOfEmptyTuples as Array<()>) // expected-warni
8787

8888
class SomeClass {}
8989

90-
// <rdar://problem/16877304> weak let's should be rejected
91-
weak let V = SomeClass() // expected-error {{'weak' must be a mutable variable, because it may change at runtime}}
90+
weak let V = SomeClass() // ok since SE-0481
91+
// expected-warning@-1 {{instance will be immediately deallocated because variable 'V' is 'weak'}}
92+
// expected-note@-2 {{'V' declared here}}
93+
// expected-note@-3 {{a strong reference is required to prevent the instance from being deallocated}}
9294

9395
let a = b ; let b = a
9496
// expected-error@-1 {{circular reference}}

test/expr/closure/closures.swift

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,12 @@ class ExplicitSelfRequiredTest {
262262
// because its `sawError` flag is set to true. To preserve the "capture 'y' was never used" warnings
263263
// above, we put these cases in their own method.
264264
func weakSelfError() {
265-
doVoidStuff({ [weak self] in x += 1 }) // expected-error {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{variable 'self' was written to, but never read}}
266-
doVoidStuffNonEscaping({ [weak self] in x += 1 }) // expected-warning {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{variable 'self' was written to, but never read}}
267-
doStuff({ [weak self] in x+1 }) // expected-error {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{variable 'self' was written to, but never read}}
268-
doVoidStuff({ [weak self] in _ = method() }) // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{variable 'self' was written to, but never read}}
269-
doVoidStuffNonEscaping({ [weak self] in _ = method() }) // expected-warning {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{variable 'self' was written to, but never read}}
270-
doStuff({ [weak self] in method() }) // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{variable 'self' was written to, but never read}}
265+
doVoidStuff({ [weak self] in x += 1 }) // expected-error {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{capture 'self' was never used}}
266+
doVoidStuffNonEscaping({ [weak self] in x += 1 }) // expected-warning {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{capture 'self' was never used}}
267+
doStuff({ [weak self] in x+1 }) // expected-error {{reference to property 'x' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{capture 'self' was never used}}
268+
doVoidStuff({ [weak self] in _ = method() }) // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{capture 'self' was never used}}
269+
doVoidStuffNonEscaping({ [weak self] in _ = method() }) // expected-warning {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{capture 'self' was never used}}
270+
doStuff({ [weak self] in method() }) // expected-error {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-warning {{capture 'self' was never used}}
271271
}
272272
}
273273

@@ -374,7 +374,7 @@ extension SomeClass {
374374
//expected-error@-3{{reference to property 'in' in closure requires explicit use of 'self' to make capture semantics explicit}}
375375
//expected-note@-4{{reference 'self.' explicitly}}
376376

377-
// expected-warning @+1 {{variable 'self' was written to, but never read}}
377+
// expected-warning @+1 {{capture 'self' was never used}}
378378
doStuff { [weak self&field] in 42 } // expected-error {{expected ']' at end of capture list}}
379379

380380
}
@@ -511,6 +511,7 @@ func lvalueCapture<T>(c: GenericClass<T>) {
511511
_ = wc
512512

513513
cc = wc!
514+
wc = cc
514515
}
515516
}
516517

@@ -1522,21 +1523,21 @@ final class AutoclosureTests {
15221523
}
15231524
}
15241525

1525-
doVoidStuff { [weak self] in // expected-warning {{variable 'self' was written to, but never read}}
1526+
doVoidStuff { [weak self] in // expected-warning {{capture 'self' was never used}}
15261527
withNonEscapingAutoclosure(bar()) // expected-error {{call to method 'bar' in closure requires explicit use of 'self' to make capture semantics explicit}}
15271528
}
15281529

1529-
doVoidStuff { [weak self] in // expected-warning {{variable 'self' was written to, but never read}}
1530+
doVoidStuff { [weak self] in // expected-warning {{capture 'self' was never used}}
15301531
withEscapingAutoclosure(bar()) // expected-error {{call to method 'bar' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-note {{reference 'self.' explicitly}}
15311532
}
15321533

1533-
doVoidStuff { [weak self] in // expected-warning {{variable 'self' was written to, but never read}}
1534+
doVoidStuff { [weak self] in // expected-warning {{capture 'self' was never used}}
15341535
doVoidStuff { // expected-note {{capture 'self' explicitly to enable implicit 'self' in this closure}}
15351536
withNonEscapingAutoclosure(bar()) // expected-error {{all to method 'bar' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-note {{reference 'self.' explicitly}}
15361537
}
15371538
}
15381539

1539-
doVoidStuff { [weak self] in // expected-warning {{variable 'self' was written to, but never read}}
1540+
doVoidStuff { [weak self] in // expected-warning {{capture 'self' was never used}}
15401541
doVoidStuff {
15411542
withEscapingAutoclosure(bar()) // expected-error {{call to method 'bar' in closure requires explicit use of 'self' to make capture semantics explicit}} expected-note {{reference 'self.' explicitly}}
15421543
}
@@ -1771,21 +1772,21 @@ class rdar129475277 {
17711772
func method() {}
17721773

17731774
func test1() {
1774-
takesEscapingWithAllowedImplicitSelf { [weak self] in // expected-warning {{variable 'self' was written to, but never read}}
1775+
takesEscapingWithAllowedImplicitSelf { [weak self] in // expected-warning {{capture 'self' was never used}}
17751776
takesEscapingWithAllowedImplicitSelf {
17761777
method() // expected-warning {{call to method 'method' in closure requires explicit use of 'self' to make capture semantics explicit}}
17771778
}
17781779
}
17791780

1780-
takesEscapingWithAllowedImplicitSelf { [weak self] in // expected-warning {{variable 'self' was written to, but never read}}
1781+
takesEscapingWithAllowedImplicitSelf { [weak self] in // expected-warning {{capture 'self' was never used}}
17811782
takesEscapingWithAllowedImplicitSelf {
17821783
doVoidStuffNonEscaping {
17831784
withNonEscapingAutoclosure(bar()) // expected-warning {{call to method 'bar' in closure requires explicit use of 'self' to make capture semantics explicit}}
17841785
}
17851786
}
17861787
}
17871788

1788-
takesEscapingWithAllowedImplicitSelf { [weak self] in // expected-warning {{variable 'self' was written to, but never read}}
1789+
takesEscapingWithAllowedImplicitSelf { [weak self] in // expected-warning {{capture 'self' was never used}}
17891790
withNonEscapingAutoclosure(bar()) // expected-warning {{call to method 'bar' in closure requires explicit use of 'self' to make capture semantics explicit}}
17901791
}
17911792
}
@@ -1818,15 +1819,15 @@ class TestExtensionOnOptionalSelf {
18181819

18191820
extension TestExtensionOnOptionalSelf? {
18201821
func foo() {
1821-
_ = { [weak self] in // expected-warning {{variable 'self' was written to, but never read}}
1822+
_ = { [weak self] in // expected-warning {{capture 'self' was never used}}
18221823
foo() // expected-error {{call to method 'foo' in closure requires explicit use of 'self' to make capture semantics explicit}}
18231824
}
18241825

18251826
_ = {
18261827
foo()
18271828
}
18281829

1829-
_ = { [weak self] in // expected-warning {{variable 'self' was written to, but never read}}
1830+
_ = { [weak self] in // expected-warning {{capture 'self' was never used}}
18301831
_ = {
18311832
foo()
18321833
}

0 commit comments

Comments
 (0)