There is a strange behaviour of the consume
operator. I apply consume
operator to a value of Copyable
type (String
to be specific) in three slightly different cases:
- consume of a parameter
- consume of a local variable
- consume of a variable declared at the top-level of main.swift (perhaps treated as a global variable)
func testA(x: consuming String) { // โ
Error: 'x' consumed more than once
let y = consume x
print(y)
print(x)
}
func testB() {
let x = "x" // โ
Error: 'x' used after consume
let y = consume x
print(y)
print(x)
}
// testC
let x = "x"
let y = consume x // โ Error: 'consume' applied to value that the compiler does not support. This is a compiler bug. Please file a bug with a small example of the bug
print(y)
I wonder if this should work and there is a bug in the compiler or this shouldn't and the error message is just needs to be refined.