From 4e93e74898f1e00c51cf3ed3edc9bf55565c96cb Mon Sep 17 00:00:00 2001 From: Pavel Yaskevich Date: Wed, 9 Jul 2025 10:59:13 -0700 Subject: [PATCH] [Concurrency] Don't downgrade explicit isolation attribute clashes The compiler shouldn't accept mismatch in explicit isolation attributes because it could lead to incorrect isolation selection. Resolves: rdar://155589753 (cherry picked from commit a9373c0f3f9f7764751880569fc8ab64ddb2c994) --- lib/Sema/TypeCheckAttr.cpp | 3 --- test/Concurrency/isolated_parameters.swift | 10 +++++----- test/attr/execution_behavior_attrs.swift | 4 ++-- test/attr/global_actor.swift | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/Sema/TypeCheckAttr.cpp b/lib/Sema/TypeCheckAttr.cpp index d0cef2d54be9e..eab64da3e5ea1 100644 --- a/lib/Sema/TypeCheckAttr.cpp +++ b/lib/Sema/TypeCheckAttr.cpp @@ -4346,7 +4346,6 @@ static void checkGlobalActorAttr( attributes[1]) .highlight(attributes[0]->getRangeWithAt()) .highlight(attributes[1]->getRangeWithAt()) - .warnUntilSwiftVersion(6) .fixItRemove(attributes[1]->getRangeWithAt()); return; } @@ -4357,7 +4356,6 @@ static void checkGlobalActorAttr( .highlight(attributes[0]->getRangeWithAt()) .highlight(attributes[1]->getRangeWithAt()) .highlight(attributes[2]->getRangeWithAt()) - .warnUntilSwiftVersion(6) .fixItRemove(attributes[1]->getRangeWithAt()) .fixItRemove(attributes[2]->getRangeWithAt()); return; @@ -4370,7 +4368,6 @@ static void checkGlobalActorAttr( .highlight(attributes[1]->getRangeWithAt()) .highlight(attributes[2]->getRangeWithAt()) .highlight(attributes[3]->getRangeWithAt()) - .warnUntilSwiftVersion(6) .fixItRemove(attributes[1]->getRangeWithAt()) .fixItRemove(attributes[2]->getRangeWithAt()) .fixItRemove(attributes[3]->getRangeWithAt()); diff --git a/test/Concurrency/isolated_parameters.swift b/test/Concurrency/isolated_parameters.swift index d878afa483bd8..0b05c7c894a3c 100644 --- a/test/Concurrency/isolated_parameters.swift +++ b/test/Concurrency/isolated_parameters.swift @@ -339,15 +339,15 @@ func isolatedClosures() { } } -// expected-warning@+3 {{global function 'allOfEm' has multiple actor-isolation attributes (@MainActor and 'nonisolated')}} -// expected-warning@+2 {{global function with 'isolated' parameter cannot be 'nonisolated'; this is an error in the Swift 6 language mode}}{{12-24=}} -// expected-warning@+1 {{global function with 'isolated' parameter cannot have a global actor; this is an error in the Swift 6 language mode}}{{1-12=}} +#if ALLOW_TYPECHECKER_ERRORS + +// expected-typechecker-error@+3 {{global function 'allOfEm' has multiple actor-isolation attributes (@MainActor and 'nonisolated')}} +// expected-typechecker-warning@+2 {{global function with 'isolated' parameter cannot be 'nonisolated'; this is an error in the Swift 6 language mode}}{{12-24=}} +// expected-typechecker-warning@+1 {{global function with 'isolated' parameter cannot have a global actor; this is an error in the Swift 6 language mode}}{{1-12=}} @MainActor nonisolated func allOfEm(_ a: isolated A) { a.f() } -#if ALLOW_TYPECHECKER_ERRORS - @MainActor class MAClass { // expected-typechecker-note@+2 {{previous 'isolated' parameter 'a'}} diff --git a/test/attr/execution_behavior_attrs.swift b/test/attr/execution_behavior_attrs.swift index ee5ba48c3d908..c9babb24a565c 100644 --- a/test/attr/execution_behavior_attrs.swift +++ b/test/attr/execution_behavior_attrs.swift @@ -99,11 +99,11 @@ struct TestAttributeCollisions { } @MainActor @concurrent func testGlobalActor() async {} - // expected-warning @-1 {{instance method 'testGlobalActor()' has multiple actor-isolation attributes (@MainActor and @concurrent)}} + // expected-error@-1 {{instance method 'testGlobalActor()' has multiple actor-isolation attributes (@MainActor and @concurrent)}} nonisolated(nonsending) nonisolated func testNonIsolatedCaller() async {} // expected-error {{duplicate modifier}} expected-note {{modifier already specified here}} @MainActor nonisolated(nonsending) func testGlobalActorCaller() async {} - // expected-warning@-1 {{instance method 'testGlobalActorCaller()' has multiple actor-isolation attributes (@MainActor and 'nonisolated(nonsending)')}} + // expected-error@-1 {{instance method 'testGlobalActorCaller()' has multiple actor-isolation attributes (@MainActor and 'nonisolated(nonsending)')}} nonisolated(nonsending) func testCaller(arg: isolated MainActor) async {} // expected-error@-1 {{cannot use 'nonisolated(nonsending)' on instance method 'testCaller(arg:)' because it has an isolated parameter: 'arg'}} diff --git a/test/attr/global_actor.swift b/test/attr/global_actor.swift index da21d2f257d8a..459e79285945d 100644 --- a/test/attr/global_actor.swift +++ b/test/attr/global_actor.swift @@ -98,7 +98,7 @@ struct Container { // Redundant attributes // ----------------------------------------------------------------------- extension SomeActor { - @GA1 nonisolated func conflict1() { } // expected-warning {{instance method 'conflict1()' has multiple actor-isolation attributes (@GA1 and 'nonisolated')}} + @GA1 nonisolated func conflict1() { } // expected-error {{instance method 'conflict1()' has multiple actor-isolation attributes (@GA1 and 'nonisolated')}} }