Skip to content

Commit 3b2c3d2

Browse files
authored
Merge pull request #36473 from DougGregor/global-actor-function-type-conversion
2 parents f17b7e2 + e50a944 commit 3b2c3d2

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

lib/AST/ASTDumper.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3837,6 +3837,11 @@ namespace {
38373837
T->getClangTypeInfo().dump(os, ctx);
38383838
printField("clang_type", os.str());
38393839
}
3840+
3841+
if (Type globalActor = T->getGlobalActor()) {
3842+
printField("global_actor", globalActor.getString());
3843+
}
3844+
38403845
printAnyFunctionParams(T->getParams(), "input");
38413846
Indent -=2;
38423847
printRec("output", T->getResult());

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,11 +2025,16 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
20252025
return getTypeMatchFailure(locator);
20262026
} else if (func1->getGlobalActor()) {
20272027
// Cannot remove a global actor.
2028+
if (!shouldAttemptFixes())
2029+
return getTypeMatchFailure(locator);
2030+
20282031
auto *fix = MarkGlobalActorFunction::create(
20292032
*this, func1, func2, getConstraintLocator(locator));
20302033

20312034
if (recordFix(fix))
20322035
return getTypeMatchFailure(locator);
2036+
} else if (kind < ConstraintKind::Subtype) {
2037+
return getTypeMatchFailure(locator);
20332038
}
20342039
}
20352040

test/Concurrency/global_actor_function_types.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,19 @@ func testClosuresOld() {
9393
return i
9494
}
9595
}
96+
97+
// Test conversions that happen in various structural positions.
98+
struct X<T> { } // expected-note{{arguments to generic parameter 'T' ('() -> Void' and '@SomeGlobalActor () -> Void') are expected to be equal}}
99+
100+
func f(_: (@SomeGlobalActor () -> Void)?) { }
101+
102+
func g(fn: (() -> Void)?) {
103+
f(fn)
104+
}
105+
106+
func f2(_ x: X<@SomeGlobalActor () -> Void>) {
107+
g2(x) // expected-error{{converting function value of type '@SomeGlobalActor () -> Void' to '() -> Void' loses global actor 'SomeGlobalActor'}}
108+
}
109+
func g2(_ x: X<() -> Void>) {
110+
f2(x) // expected-error{{cannot convert value of type 'X<() -> Void>' to expected argument type 'X<@SomeGlobalActor () -> Void>'}}
111+
}

0 commit comments

Comments
 (0)