Skip to content

Commit 507c405

Browse files
committed
[SE-0470] Check uses of isolated conformances in collection literals
Fixes rdar://151646584.
1 parent 65d9f5f commit 507c405

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,6 +3488,13 @@ namespace {
34883488
getDeclContext(), RefineConformances{*this});
34893489
}
34903490

3491+
if (auto *collectionExpr = dyn_cast<CollectionExpr>(expr)) {
3492+
checkIsolatedConformancesInContext(
3493+
collectionExpr->getInitializer(),
3494+
collectionExpr->getLoc(),
3495+
getDeclContext(), RefineConformances{*this});
3496+
}
3497+
34913498
return Action::Continue(expr);
34923499
}
34933500

test/Concurrency/isolated_conformance.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,12 @@ func testIsolatedConformancesOnAssociatedTypes(hc: HoldsC, c: C) {
235235
// associated type.
236236
HoldsC.acceptSendableAliased(C.self)
237237
}
238+
239+
240+
struct MyHashable: @MainActor Hashable {
241+
var counter = 0
242+
}
243+
244+
@concurrent func testMyHashableSet() async {
245+
let _: Set<MyHashable> = [] // expected-warning{{main actor-isolated conformance of 'MyHashable' to 'Hashable' cannot be used in nonisolated context}}
246+
}

0 commit comments

Comments
 (0)