From 0df5ca34cc2c122c682a7d3d3b01f78a3f965db3 Mon Sep 17 00:00:00 2001 From: Danil Koshnarev Date: Fri, 7 Nov 2025 13:19:02 +0200 Subject: [PATCH] Fix Issue #68212: Preserve type specialization in typealias extensions When extending a partially specialized generic typealias (e.g., 'typealias IntField = Field'), the compiler was losing type specialization information and returning only the base nominal type (Field), causing type checker errors when trying to use specialized type information in the extension body. This fix ensures that we return the typealias type itself, which properly preserves the partial specialization constraints. The previous logic used isPassThroughTypealias() to decide between returning extendedType or extendedNominal->getDeclaredType(). When the latter was returned, it lost the specialization information (e.g., that Value == Int in IntField). By always returning extendedType for typealias extensions, we preserve the full type information and allow the type checker to correctly resolve types in the extension body. Fixes: https://github.com/swiftlang/swift/issues/68212 --- lib/Sema/TypeCheckDecl.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp index caa3bf87a9b8..dd62ac9ac42b 100644 --- a/lib/Sema/TypeCheckDecl.cpp +++ b/lib/Sema/TypeCheckDecl.cpp @@ -3068,10 +3068,10 @@ ExtendedTypeRequest::evaluate(Evaluator &eval, ExtensionDecl *ext) const { if (auto *aliasDecl = dyn_cast(unboundGeneric->getDecl())) { auto underlyingType = aliasDecl->getUnderlyingType(); if (auto extendedNominal = underlyingType->getAnyNominal()) { - return TypeChecker::isPassThroughTypealias( - aliasDecl, extendedNominal) - ? extendedType - : extendedNominal->getDeclaredType(); + // Return the typealias type itself to preserve specialization info. + // Previously we returned the nominal's declared type which lost + // information about partial type specialization. See Issue #68212. + return extendedType; } if (underlyingType->is()) {