mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
The reason why we are doing this is that this combination of read/set forces the compiler to emit a copy if we want to emit a modify operation. The reason why we are forced to emit such a copy is that: 1. _read provides a guaranteed value in memory 2. performing a modify requires an owned value in memory. This together implies that the only way we can do this is to copy from the _read into temporary memory. But we have a noncopyable type so we can't do this. rdar://112915525
65 lines
2.5 KiB
Swift
65 lines
2.5 KiB
Swift
// RUN: %target-typecheck-verify-swift
|
|
// RUN: %target-typecheck-verify-swift -enable-library-evolution
|
|
|
|
@frozen
|
|
public struct NonCopyableS : ~Copyable {}
|
|
@frozen
|
|
public enum NonCopyableE : ~Copyable {}
|
|
|
|
public struct S {
|
|
public var x: NonCopyableS { // expected-error {{noncopyable variable cannot provide a read and set accessor}}
|
|
_read { fatalError() }
|
|
set { fatalError() }
|
|
}
|
|
public var x2: NonCopyableE { // expected-error {{noncopyable variable cannot provide a read and set accessor}}
|
|
_read { fatalError() }
|
|
set { fatalError() }
|
|
}
|
|
public subscript(x x: Int) -> NonCopyableS { // expected-error {{noncopyable subscript cannot provide a read and set accessor}}
|
|
_read { fatalError() }
|
|
set { fatalError() }
|
|
}
|
|
public subscript(y y: Int) -> NonCopyableE { // expected-error {{noncopyable subscript cannot provide a read and set accessor}}
|
|
_read { fatalError() }
|
|
set { fatalError() }
|
|
}
|
|
}
|
|
|
|
public class C {
|
|
public var x: NonCopyableS { // expected-error {{noncopyable variable cannot provide a read and set accessor}}
|
|
_read { fatalError() }
|
|
set { fatalError() }
|
|
}
|
|
public var x2: NonCopyableE { // expected-error {{noncopyable variable cannot provide a read and set accessor}}
|
|
_read { fatalError() }
|
|
set { fatalError() }
|
|
}
|
|
public subscript(x x: Int) -> NonCopyableS { // expected-error {{noncopyable subscript cannot provide a read and set accessor}}
|
|
_read { fatalError() }
|
|
set { fatalError() }
|
|
}
|
|
public subscript(y y: Int) -> NonCopyableE { // expected-error {{noncopyable subscript cannot provide a read and set accessor}}
|
|
_read { fatalError() }
|
|
set { fatalError() }
|
|
}
|
|
}
|
|
|
|
public enum E {
|
|
public var x: NonCopyableS { // expected-error {{noncopyable variable cannot provide a read and set accessor}}
|
|
_read { fatalError() }
|
|
set { fatalError() }
|
|
}
|
|
public var x2: NonCopyableE { // expected-error {{noncopyable variable cannot provide a read and set accessor}}
|
|
_read { fatalError() }
|
|
set { fatalError() }
|
|
}
|
|
public subscript(x x: Int) -> NonCopyableS { // expected-error {{noncopyable subscript cannot provide a read and set accessor}}
|
|
_read { fatalError() }
|
|
set { fatalError() }
|
|
}
|
|
public subscript(y y: Int) -> NonCopyableE { // expected-error {{noncopyable subscript cannot provide a read and set accessor}}
|
|
_read { fatalError() }
|
|
set { fatalError() }
|
|
}
|
|
}
|