mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Pass through the location of the equal '=' token for pattern binding decl entries, and use this location for the immediate deallocation diagnostic. Previously, we were just diagnosing on the start of the initialiser expression. Additionally, this commit moves the call to `diagnoseUnownedImmediateDeallocation` from `typeCheckBinding` to `typeCheckPatternBinding`. This not only gives us easier access to the PBD entry, but also avoids calling the diagnostic logic for statement conditions such as `if let x = <expr>`. We currently never diagnose on these anyway, as the 'weak' and 'unowned' keywords cannot be applied to such bindings. Resolves [SR-7340](https://bugs.swift.org/browse/SR-7340).
23 lines
1.2 KiB
Swift
23 lines
1.2 KiB
Swift
// RUN: %target-swift-frontend -typecheck %s 2>&1 | %FileCheck %s
|
|
|
|
// Ensure we emit the warnings on the equal '=' tokens.
|
|
class C {}
|
|
|
|
weak var c1 = C() // CHECK: [[@LINE]]:13: warning: instance will be immediately deallocated because variable 'c1' is 'weak'
|
|
|
|
weak var c2: C? = C() // CHECK: [[@LINE]]:17: warning: instance will be immediately deallocated because variable 'c2' is 'weak'
|
|
|
|
weak var (c3, c4) = (C(), C())
|
|
// CHECK: [[@LINE-1]]:19: warning: instance will be immediately deallocated because variable 'c3' is 'weak'
|
|
// CHECK: [[@LINE-2]]:19: warning: instance will be immediately deallocated because variable 'c4' is 'weak'
|
|
|
|
weak var (c5, c6): (C?, C?) = (C(), C())
|
|
// CHECK: [[@LINE-1]]:29: warning: instance will be immediately deallocated because variable 'c5' is 'weak'
|
|
// CHECK: [[@LINE-2]]:29: warning: instance will be immediately deallocated because variable 'c6' is 'weak'
|
|
|
|
unowned let c7 = C(), c8: C = C()
|
|
// CHECK: [[@LINE-1]]:16: warning: instance will be immediately deallocated because variable 'c7' is 'unowned'
|
|
// CHECK: [[@LINE-2]]:29: warning: instance will be immediately deallocated because variable 'c8' is 'unowned'
|
|
|
|
c1 = C() // CHECK: [[@LINE]]:4: warning: instance will be immediately deallocated because variable 'c1' is 'weak'
|