mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Presently subtype constraint is considered a candidate for contraction via `shouldContractEdge` when left-hand side of the subtype constraint is an inout type with type variable inside. Although it's intended to be used only in combination with BindParam constraint assigned to the same variable, that is actually never checked and contraction of subtype constraint like that is invalid. Resolves: rdar://problem/34333874
43 lines
719 B
Swift
43 lines
719 B
Swift
// RUN: %target-run-simple-swift
|
|
// REQUIRES: executable_test
|
|
|
|
class C {
|
|
var a: Int = 0
|
|
var b: Int = 0
|
|
}
|
|
|
|
@inline(never)
|
|
func foo<T>(_ item: T, update: (inout T) throws -> Void) rethrows -> T {
|
|
var this = item
|
|
try update(&this)
|
|
return this
|
|
}
|
|
|
|
// Test single statement closure because it's type-checked
|
|
// together with the call to `foo`
|
|
|
|
let rdar34333874_1 = foo(C()) {
|
|
$0.a = 42
|
|
}
|
|
|
|
// The multi-statement closure which is type-checked
|
|
// separately from call to `foo`
|
|
|
|
let rdar34333874_2 = foo(C()) {
|
|
$0.a = 42
|
|
$0.b = 0
|
|
}
|
|
|
|
print(rdar34333874_1)
|
|
print(rdar34333874_2)
|
|
|
|
// Example which avoids mutating fields of the class
|
|
|
|
@inline(never)
|
|
func bar(_ o : C) {
|
|
let _ = foo(o) { (item) in
|
|
}
|
|
}
|
|
|
|
bar(C())
|