Skip to content

if/else works but ?? causes data race warning #74843

@jasonbobier

Description

@jasonbobier

Description

I have a case where I can use an if/else block, but can't use ?? without a data race warning

Reproduction

// This works
cbCentralManager.retrieveConnectedPeripherals(withServices: services.map { $0.uuid })
	.map {
		if let peripheral = ($0.delegate as? Peripheral) {
			return peripheral
		} else {
			return Peripheral(cbPeripheral: $0, queue: self.queue)
		}
	}

// This causes: 'self'-isolated '$0' is captured by a actor-isolated closure. actor-isolated uses in closure may race against later nonisolated uses
cbCentralManager.retrieveConnectedPeripherals(withServices: services.map { $0.uuid })
	.map { ($0.delegate as? Peripheral) ?? Peripheral(cbPeripheral: $0, queue: self.queue) }

Expected behavior

The ?? case would not cause a data race warning.

Environment

Xcode Version 16.0 beta 2 (16A5171r) in Swift 6 language mode

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    SILactor isolationFeature → concurrency: Actor isolationbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.closuresFeature: closurescompilerThe Swift compiler itselfconcurrencyFeature: umbrella label for concurrency language featuresexpressionsFeature: expressionsnil-coalescing operatorFeature → operators: The nil-coalescing operator `??`operatorsFeature: operatorstype checkerArea → compiler: Semantic analysisunexpected warningBug: Unexpected warning

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions