Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'consume' applied to value that the compiler does not support #72615

Open
mr-swifter opened this issue Mar 27, 2024 · 0 comments
Open

'consume' applied to value that the compiler does not support #72615

mr-swifter opened this issue Mar 27, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. ownership Feature: Ownership modifiers and semantics

Comments

@mr-swifter
Copy link

mr-swifter commented Mar 27, 2024

Description

I trying to use consume operator, but it lead to compilation error with 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

Basically I do very similar to what is described in example at SE-0366

Reproduction

func doStuffUniquely(with value: consuming [Int]) {
  // If we received the last remaining reference to `value`, we'd like
  // to be able to efficiently update it without incurring more copies.
  var newValue = consume value
  newValue.append(42)
}

func test() {
  var x: [Int] = [1,2,3]
  
  // x is appended to. After this point, we know that x is unique. We want to
  // preserve that property.
  x.append(5)
  
  // Pass the current value of x off to another function, that
  doStuffUniquely(with: consume x) // DOESN'T COMPILE WITH 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 

  // Reset x to a new value. Since we don't use the old value anymore,
  x = []
  doMoreStuff(with: &x)
}

func doMoreStuff(with value: inout [Int]) {
}

Expected behavior

Compiles normally and works

Environment

swift-driver version: 1.90.11.1 Apple Swift version 5.10 (swiftlang-5.10.0.13 clang-1500.3.9.4)
Target: arm64-apple-macosx14.0

Additional information

No response

@mr-swifter mr-swifter added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Mar 27, 2024
@hborla hborla added ownership Feature: Ownership modifiers and semantics and removed triage needed This issue needs more specific labels labels Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. ownership Feature: Ownership modifiers and semantics
Projects
None yet
Development

No branches or pull requests

2 participants