You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When struct S below is declared ~Copyable, Xcode 15.3 beta tags its instance (s) as being consumed more than once. But if S is declared without ~Copyable, Xcode doesn't give an error message and the consuming function value() can be called more than once on the instance.
Reproduction
structS:~Copyable {letv="hi"consumingfunc value()->String{return v }}func f(){lets=S()// Xcode 15.3 beta error message: 's' consumed more than onceprint(s.value())print(s.value())}f()
but:
structSc{// or classletv="hi"consumingfunc value()->String{return v }}func g(){lets=Sc()// no error messageprint(s.value())print(s.value())// prints out a second time}g()
Expected behavior
Xcode gives the same error message in both cases and the second call to s.value() an error (as per SE-0377).
Environment
Xcode 15.3 beta on macOS 14.4 beta CLI.
Additional information
No response
The text was updated successfully, but these errors were encountered:
eecs441staff
added
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
triage needed
This issue needs more specific labels
labels
Feb 1, 2024
tbkka
removed
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
triage needed
This issue needs more specific labels
labels
Feb 1, 2024
This is expected. The compiler is allowed to freely make copies of a Copyable type. I've added comments below to clarify how this works in this case:
func g() {
let s = Sc()
// Because `s` will be used again, the compiler will actually
// create a copy for this first call. That copy gets consumed here:
print(s.value())
// The original value can then be consumed here:
print(s.value())
}
Description
When
struct Sbelow is declared~Copyable, Xcode 15.3 beta tags its instance (s) as being consumed more than once. But ifSis declared without~Copyable, Xcode doesn't give an error message and the consuming functionvalue()can be called more than once on the instance.Reproduction
but:
Expected behavior
Xcode gives the same error message in both cases and the second call to
s.value()an error (as per SE-0377).Environment
Xcode 15.3 beta on macOS 14.4 beta CLI.
Additional information
No response
The text was updated successfully, but these errors were encountered: