Skip to content

Commit b37a924

Browse files
authored
Merge pull request #72337 from xedin/rdar-123356909
[Sema] EffectsChecker: Adjust application classifier to skip invertib…
2 parents 9504de5 + 697e1fb commit b37a924

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,8 +1302,13 @@ class ApplyClassifier {
13021302
if (!fnType) return Classification::forInvalidCode();
13031303

13041304
auto fnRef = AbstractFunction::getAppliedFn(E);
1305-
auto conformances = fnRef.getSubstitutions().getConformances();
1306-
const auto hasAnyConformances = !conformances.empty();
1305+
auto substitutions = fnRef.getSubstitutions();
1306+
const bool hasAnyConformances =
1307+
llvm::any_of(substitutions.getConformances(),
1308+
[](const ProtocolConformanceRef conformance) {
1309+
auto *requirement = conformance.getRequirement();
1310+
return !requirement->getInvertibleProtocolKind();
1311+
});
13071312

13081313
// If the function doesn't have any effects or conformances, we're done
13091314
// here.
@@ -1347,21 +1352,21 @@ class ApplyClassifier {
13471352
switch (auto polyKind = fnRef.getPolymorphicEffectKind(kind)) {
13481353
case PolymorphicEffectKind::AsyncSequenceRethrows:
13491354
case PolymorphicEffectKind::ByConformance: {
1350-
auto substitutions = fnRef.getSubstitutions();
1351-
auto requirements =
1352-
substitutions.getGenericSignature().getRequirements();
1353-
auto conformances = substitutions.getConformances();
1355+
auto requirements = substitutions.getGenericSignature()
1356+
.withoutMarkerProtocols()
1357+
.getRequirements();
13541358
for (const auto &req : requirements) {
13551359
if (req.getKind() != RequirementKind::Conformance)
13561360
continue;
13571361

1358-
auto conformanceRef = conformances.front();
1359-
conformances = conformances.drop_front();
1360-
13611362
Type type = req.getFirstType().subst(substitutions);
1363+
1364+
auto conformanceRef = substitutions.lookupConformance(
1365+
req.getFirstType()->getCanonicalType(), req.getProtocolDecl());
1366+
assert(conformanceRef);
1367+
13621368
result.merge(classifyConformance(type, conformanceRef, kind));
13631369
}
1364-
assert(conformances.empty());
13651370

13661371
// 'ByConformance' is a superset of 'ByClosure', so check for
13671372
// closure arguments too.

test/Concurrency/async_throwing.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,28 @@ func asyncTest() async {
150150
// ignore
151151
}
152152
}
153+
154+
// rdar://123356909 - spurious error - `call can throw, but it is not marked with 'try' and the error is not handled`
155+
do {
156+
struct AsyncTestSequence<Element>: AsyncSequence {
157+
typealias Element = Element
158+
159+
let stream: AsyncMapSequence<AsyncStream<[String : Any]>, Element>
160+
161+
init(stream: AsyncMapSequence<AsyncStream<[String : Any]>, Element>) {
162+
self.stream = stream
163+
}
164+
165+
func makeAsyncIterator() -> AsyncIterator {
166+
.init(iterator: stream.makeAsyncIterator())
167+
}
168+
169+
struct AsyncIterator: AsyncIteratorProtocol {
170+
var iterator: AsyncMapSequence<AsyncStream<[String : Any]>, Element>.AsyncIterator
171+
172+
mutating func next() async -> Element? {
173+
await iterator.next() // Ok
174+
}
175+
}
176+
}
177+
}

0 commit comments

Comments
 (0)