mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Some notes: 1. I implemented this as a contextual keyword that can only apply directly to lvalues. This ensures that we can still call functions called copy, define variables named copy, etc. I added tests for both the c++ and swift-syntax based parsers to validate this. So there shouldn't be any source breaks. 2. I did a little bit of type checker work to ensure that we do not treat copy_expr's result as an lvalue. Otherwise, one could call mutating functions on it or assign to it, which we do not want since the result of copy_value is 3. As expected, by creating a specific expr, I was able to have much greater control of the SILGen codegen and thus eliminate extraneous copies and other weirdness than if we used a function and had to go through SILGenApply. rdar://101862423
12 lines
278 B
Swift
12 lines
278 B
Swift
// RUN: %target-typecheck-verify-swift -disable-availability-checking -enable-experimental-feature NoImplicitCopy
|
|
|
|
class Klass {}
|
|
|
|
func consumeKlass(_ x: __owned Klass) {}
|
|
|
|
func testNoImplicitCopyWorks() {
|
|
@_noImplicitCopy let x = Klass()
|
|
let _ = copy x
|
|
consumeKlass(x)
|
|
}
|