From 4a8ada3fb071b70ec70cfc4533de0e1308064e13 Mon Sep 17 00:00:00 2001 From: Dario Rexin Date: Thu, 10 Apr 2025 15:13:00 -0700 Subject: [PATCH] [IRGen] Set generic context before getting call emission in visitFullApplySite rdar://149007227 Without the generic context, the result type can't be mapped into the current context, causing the compiler to crash. --- lib/IRGen/IRGenSIL.cpp | 7 ++++--- test/IRGen/typed_throws.swift | 12 ++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/IRGen/IRGenSIL.cpp b/lib/IRGen/IRGenSIL.cpp index 18105502da8b9..ba574ae5d7683 100644 --- a/lib/IRGen/IRGenSIL.cpp +++ b/lib/IRGen/IRGenSIL.cpp @@ -3850,6 +3850,10 @@ void IRGenSILFunction::visitFullApplySite(FullApplySite site) { } } + // Lower the arguments and return value in the callee's generic context. + GenericContextScope scope(IGM, + origCalleeType->getInvocationGenericSignature()); + Explosion llArgs; WitnessMetadata witnessMetadata; auto emission = getCallEmissionForLoweredValue( @@ -3862,9 +3866,6 @@ void IRGenSILFunction::visitFullApplySite(FullApplySite site) { emission->begin(); - // Lower the arguments and return value in the callee's generic context. - GenericContextScope scope(IGM, origCalleeType->getInvocationGenericSignature()); - auto &calleeFP = emission->getCallee().getFunctionPointer(); // Allocate space for the coroutine buffer. diff --git a/test/IRGen/typed_throws.swift b/test/IRGen/typed_throws.swift index d44b65afd2b14..f4581f0d039e1 100644 --- a/test/IRGen/typed_throws.swift +++ b/test/IRGen/typed_throws.swift @@ -359,3 +359,15 @@ struct SomeStruct { func someFunc() async throws(SmallError) -> SomeStruct { SomeStruct(x: 42, y: 23, z: 25) } + +// Used to crash the compiler -- https://github.com/swiftlang/swift/issues/80732 +protocol PAssoc: AnyObject { + associatedtype T + func foo() async throws(SmallError) -> (any PAssoc) +} + +class MyProtocolImpl: PAssoc { + func foo() async throws(SmallError) -> (any PAssoc) { + fatalError() + } +}