Skip to content

Commit d8a1649

Browse files
authored
Merge pull request #79666 from slavapestov/fix-rdar144644342
Sema: Fix Sendable generic parameter fixit
2 parents 39acb9a + e37a2d0 commit d8a1649

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

lib/SILOptimizer/Mandatory/SendNonSendable.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,15 +2475,13 @@ static void addSendableFixIt(const NominalTypeDecl *nominal,
24752475
/// Add Fix-It text for the given generic param declaration type to adopt
24762476
/// Sendable.
24772477
static void addSendableFixIt(const GenericTypeParamDecl *genericArgument,
2478-
InFlightDiagnostic &diag, bool unchecked) {
2478+
InFlightDiagnostic &diag) {
24792479
if (genericArgument->getInherited().empty()) {
24802480
auto fixItLoc = genericArgument->getLoc();
2481-
diag.fixItInsertAfter(fixItLoc,
2482-
unchecked ? ": @unchecked Sendable" : ": Sendable");
2481+
diag.fixItInsertAfter(fixItLoc, ": Sendable");
24832482
} else {
24842483
auto fixItLoc = genericArgument->getInherited().getEndLoc();
2485-
diag.fixItInsertAfter(fixItLoc,
2486-
unchecked ? ", @unchecked Sendable" : ", Sendable");
2484+
diag.fixItInsertAfter(fixItLoc, " & Sendable");
24872485
}
24882486
}
24892487

@@ -2664,7 +2662,7 @@ void NonSendableIsolationCrossingResultDiagnosticEmitter::emit() {
26642662
genericParamTypeDecl->getModuleContext() == moduleDecl) {
26652663
auto diag = genericParamTypeDecl->diagnose(
26662664
diag::rbi_add_generic_parameter_sendable_conformance, type);
2667-
addSendableFixIt(genericParamTypeDecl, diag, /*unchecked=*/false);
2665+
addSendableFixIt(genericParamTypeDecl, diag);
26682666
return;
26692667
}
26702668
}

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -767,15 +767,13 @@ static void addSendableFixIt(
767767
/// Add Fix-It text for the given generic param declaration type to adopt
768768
/// Sendable.
769769
static void addSendableFixIt(const GenericTypeParamDecl *genericArgument,
770-
InFlightDiagnostic &diag, bool unchecked) {
770+
InFlightDiagnostic &diag) {
771771
if (genericArgument->getInherited().empty()) {
772772
auto fixItLoc = genericArgument->getLoc();
773-
diag.fixItInsertAfter(fixItLoc,
774-
unchecked ? ": @unchecked Sendable" : ": Sendable");
773+
diag.fixItInsertAfter(fixItLoc, ": Sendable");
775774
} else {
776775
auto fixItLoc = genericArgument->getInherited().getEndLoc();
777-
diag.fixItInsertAfter(fixItLoc,
778-
unchecked ? ", @unchecked Sendable" : ", Sendable");
776+
diag.fixItInsertAfter(fixItLoc, " & Sendable");
779777
}
780778
}
781779

@@ -1022,7 +1020,7 @@ static bool diagnoseSingleNonSendableType(
10221020
genericParamTypeDecl->getModuleContext() == module) {
10231021
auto diag = genericParamTypeDecl->diagnose(
10241022
diag::add_generic_parameter_sendable_conformance, type);
1025-
addSendableFixIt(genericParamTypeDecl, diag, /*unchecked=*/false);
1023+
addSendableFixIt(genericParamTypeDecl, diag);
10261024
}
10271025
}
10281026
}

test/Concurrency/sendable_checking.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ protocol P {
131131
func foo2<T : Sendable>(x : T) async -> ()
132132

133133
func bar2<T>(x : T) async -> ()
134-
// expected-note@-1 {{consider making generic parameter 'T' conform to the 'Sendable' protocol}}
134+
// expected-note@-1 {{consider making generic parameter 'T' conform to the 'Sendable' protocol}} {{14-14=: Sendable}}
135+
136+
func bar3<T: Equatable>(x : T) async -> ()
137+
// expected-note@-1 {{consider making generic parameter 'T' conform to the 'Sendable' protocol}} {{25-25= & Sendable}}
135138
}
136139

137140
// Make sure conformance to protocols checks sendability of
@@ -147,6 +150,9 @@ protocol P {
147150

148151
func bar2<T>(x : T) -> () {}
149152
// expected-warning@-1 {{non-sendable parameter type 'T' cannot be sent from caller of protocol requirement 'bar2(x:)' into actor-isolated implementation}}
153+
154+
func bar3<T: Equatable>(x : T) -> () {}
155+
// expected-warning@-1 {{non-sendable parameter type 'T' cannot be sent from caller of protocol requirement 'bar3(x:)' into actor-isolated implementation}}
150156
}
151157

152158
@available(SwiftStdlib 5.1, *)
@@ -163,7 +169,11 @@ class Super {
163169

164170
@MainActor
165171
func bar2<T>(x: T) async {}
166-
// expected-note@-1 {{consider making generic parameter 'T' conform to the 'Sendable' protocol}}
172+
// expected-note@-1 {{consider making generic parameter 'T' conform to the 'Sendable' protocol}} {{14-14=: Sendable}}
173+
174+
@MainActor
175+
func bar3<T: Equatable>(x: T) async {}
176+
// expected-note@-1 {{consider making generic parameter 'T' conform to the 'Sendable' protocol}} {{25-25= & Sendable}}
167177
}
168178

169179
// Make sure isolation crossing overrides check sendability
@@ -179,6 +189,9 @@ class Sub : Super {
179189

180190
override nonisolated func bar2<T>(x: T) async {}
181191
// expected-warning@-1 {{non-sendable parameter type 'T' cannot be sent from caller of superclass instance method 'bar2(x:)' into nonisolated override}}
192+
193+
override nonisolated func bar3<T>(x: T) async {}
194+
// expected-warning@-1 {{non-sendable parameter type 'T' cannot be sent from caller of superclass instance method 'bar3(x:)' into nonisolated override}}
182195
}
183196

184197
@available(SwiftStdlib 5.1, *)

0 commit comments

Comments
 (0)