Skip to content

compiler crash: Abstract conformance with bad subject type #85084

@lukaskollmer

Description

@lukaskollmer

Description

the program below crashes the compiler, because of the protocol extension.

Note: the types here are correct (ie, eveything compiles and works just fine when the extension is removed) and initializing S1 directly (instead of attempting to go through the extension) works as expected.

Reproduction

protocol P1 {}

protocol P2 {
    associatedtype U
}

protocol P3<T> {
    associatedtype T: P2
}

struct S1<T: P2>: P3 where T.U: P1 {}

extension P3 where Self == S1<T> {
    static var a: S1<T> {
        S1<T>()
    }
}

Stack dump

error: compile command failed due to signal 6 (use -v to see invocation)
Abstract conformance with bad subject type:
(bound_generic_struct_type decl="test.(file).S1@test.swift:11:8"
  (error_type))
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file test.swift -target arm64-apple-macosx15.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX26.0.sdk -color-diagnostics -Xcc -fcolor-diagnostics -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -no-auto-bridging-header-chaining -module-name test -disable-clang-spi -target-sdk-version 26.0 -target-sdk-name macosx26.0 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -in-process-plugin-server-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -o /var/folders/wg/_pfs36w90bggmj14t3bq68x80000gn/T/TemporaryDirectory.OM3gkj/test-1.o
1.	Apple Swift version 6.2 (swiftlang-6.2.0.19.9 clang-1700.3.19.1)
2.	Compiling with effective version 5.10
3.	While evaluating request TypeCheckPrimaryFileRequest(source_file "test.swift")
4.	While evaluating request TypeCheckFunctionBodyRequest(test.(file).P3 extension._@test.swift:14:16)
5.	While evaluating request ParseAbstractFunctionBodyRequest(test.(file).P3 extension._@test.swift:14:16)
 #0 0x000000010b141bcc llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x1066f9bcc)
 #1 0x000000010b13f55c llvm::sys::RunSignalHandlers() (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x1066f755c)
 #2 0x000000010b1421f8 SignalHandler(int, __siginfo*, void*) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x1066fa1f8)
 #3 0x0000000183c5d6a4 (/usr/lib/system/libsystem_platform.dylib+0x1804ad6a4)
 #4 0x0000000183c2388c (/usr/lib/system/libsystem_pthread.dylib+0x18047388c)
 #5 0x0000000183b2ca3c (/usr/lib/system/libsystem_c.dylib+0x18037ca3c)
 #6 0x000000010656fc98 swift::AvailabilityContext::Storage::get(swift::AvailabilityRange const&, bool, llvm::ArrayRef<swift::AvailabilityContext::DomainInfo>, swift::ASTContext const&) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x101b27c98)
 #7 0x00000001069e5580 swift::MakeAbstractConformanceForGenericType::operator()(swift::CanType, swift::Type, swift::ProtocolDecl*) const (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x101f9d580)
 #8 0x00000001069eb83c (anonymous namespace)::TypeSubstituter::transformDependentMemberType(swift::DependentMemberType*, swift::TypePosition) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x101fa383c)
 #9 0x00000001069e6ac8 swift::TypeTransform<(anonymous namespace)::TypeSubstituter>::doIt(swift::Type, swift::TypePosition) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x101f9eac8)
#10 0x00000001069eb714 (anonymous namespace)::TypeSubstituter::transformDependentMemberType(swift::DependentMemberType*, swift::TypePosition) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x101fa3714)
#11 0x00000001069e6ac8 swift::TypeTransform<(anonymous namespace)::TypeSubstituter>::doIt(swift::Type, swift::TypePosition) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x101f9eac8)
#12 0x00000001069e62d8 swift::Type::subst(swift::InFlightSubstitution&) const (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x101f9e2d8)
#13 0x00000001069ade90 swift::SubstitutionMap::get(swift::GenericSignature, llvm::ArrayRef<swift::Type>, swift::InFlightSubstitution&) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x101f65e90)
#14 0x00000001069add68 swift::SubstitutionMap::get(swift::GenericSignature, swift::InFlightSubstitution&) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x101f65d68)
#15 0x00000001068696d8 swift::GenericEnvironment::getForwardingSubstitutionMap() const (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x101e216d8)
#16 0x00000001063938cc buildStorageReference(swift::AccessorDecl*, swift::AbstractStorageDecl*, (anonymous namespace)::TargetImpl, bool, bool, swift::ASTContext&) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x10194b8cc)
#17 0x0000000106399770 synthesizeCoroutineAccessorBody(swift::AccessorDecl*, swift::ASTContext&) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x101951770)
#18 0x00000001063884ec synthesizeAccessorBody(swift::AbstractFunctionDecl*, void*) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x1019404ec)
#19 0x0000000106517fd8 swift::SimpleRequest<swift::ParseAbstractFunctionBodyRequest, swift::BodyAndFingerprint (swift::AbstractFunctionDecl*), (swift::RequestFlags)4>::evaluateRequest(swift::ParseAbstractFunctionBodyRequest const&, swift::Evaluator&) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x101acffd8)
#20 0x0000000106729fa0 swift::AbstractFunctionDecl::getBody(bool) const (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x101ce1fa0)
#21 0x00000001067284ac swift::AbstractFunctionDecl::getMacroExpandedBody() const (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x101ce04ac)
#22 0x0000000106376840 swift::TypeCheckFunctionBodyRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*) const (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x10192e840)
#23 0x00000001067dabe0 swift::TypeCheckFunctionBodyRequest::OutputType swift::Evaluator::getResultUncached<swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType)::'lambda'()>(swift::TypeCheckFunctionBodyRequest const&, swift::TypeCheckFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType)::'lambda'()) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x101d92be0)
#24 0x000000010672a930 swift::AbstractFunctionDecl::getTypecheckedBody() const (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x101ce2930)
#25 0x00000001063ced38 swift::TypeCheckPrimaryFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x101986d38)
#26 0x00000001063d5c40 swift::TypeCheckPrimaryFileRequest::OutputType swift::Evaluator::getResultUncached<swift::TypeCheckPrimaryFileRequest, swift::TypeCheckPrimaryFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckPrimaryFileRequest>(swift::Evaluator&, swift::TypeCheckPrimaryFileRequest, swift::TypeCheckPrimaryFileRequest::OutputType)::'lambda'()>(swift::TypeCheckPrimaryFileRequest const&, swift::TypeCheckPrimaryFileRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckPrimaryFileRequest>(swift::Evaluator&, swift::TypeCheckPrimaryFileRequest, swift::TypeCheckPrimaryFileRequest::OutputType)::'lambda'()) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x10198dc40)
#27 0x000000010517e1c8 bool llvm::function_ref<bool (swift::SourceFile&)>::callback_fn<swift::CompilerInstance::performSema()::$_0>(long, swift::SourceFile&) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x1007361c8)
#28 0x0000000105177850 swift::CompilerInstance::forEachFileToTypeCheck(llvm::function_ref<bool (swift::SourceFile&)>) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x10072f850)
#29 0x00000001051776e4 swift::CompilerInstance::performSema() (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x10072f6e4)
#30 0x0000000104d7e69c performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x10033669c)
#31 0x0000000104d7d68c swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x10033568c)
#32 0x0000000104cfec6c swift::mainEntry(int, char const**) (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend+0x1002b6c6c)
#33 0x0000000183882b98

Expected behavior

it should be possible to define a computed static variable on a protocol extension, if the protocol contains associated types and the type of the static variable uses these associated types.

Environment

swift-driver version: 1.127.14.1 Apple Swift version 6.2 (swiftlang-6.2.0.19.9 clang-1700.3.19.1)
Target: arm64-apple-macosx15.0

Additional information

i think the issue here is that the type we want to use for the static variable (S1) defines a constraint on its generic parameter? (which corresponds to the protocol's associated type.)
copying the constraint into the protocol extension does not fix things.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwaretriage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions