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

[SR-14876] Async let - await - compilation error #57223

Open
swift-ci opened this issue Jul 5, 2021 · 1 comment
Open

[SR-14876] Async let - await - compilation error #57223

swift-ci opened this issue Jul 5, 2021 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jul 5, 2021

Previous ID SR-14876
Radar rdar://problem/80238317
Original Reporter somu (JIRA User)
Type Bug
Environment
  • Xcode Version 13.0 beta (13A5155e)

  • iOS project that supports only iOS 15.0

  • macOS Big Sur (11.4)

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: a91d316bf25240ba8cc082b021837de8

Issue Description:

Hi,

I have the following code that throws a compilation error.

Overview

  • I have an async let p1 statement

  • Then I have 2 statements that await on p1

  • Removing one of those 2 awaits removes the error

Compilation error:
Immutable value 'p1' may only be initialized once

Tested on:

  • Xcode Version 13.0 beta (13A5155e)

  • iOS project that supports only iOS 15.0

  • macOS Big Sur (11.4)

Code:

import Foundation

func f1() {
    async {
        async let p1 = computePrice() //Immutable value 'p1' may only be initialized once
        print(await p1)
        let k = await p1
    }
}

func computePrice() async -> Int {
    await withCheckedContinuation { continuation in
        DispatchQueue.main.asyncAfter(deadline: .now() + 4) {
            continuation.resume(returning: 10)
        }
    }
}

It looks like a bug, let me know if I am missing something. Thanks.

@typesanitizer
Copy link

Reduced example

func f() async -> Int { 1 }

func g() {
    async {
        async let x = f()
        print(await x)
        let y = await x
    }
}

To work around this bug, you can create a binding for await x and reuse that later.

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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.
Projects
None yet
Development

No branches or pull requests

2 participants