Skip to content

Compiler crash "checked decl cannot have error type" starting with the development snapshot build swift-DEVELOPMENT-SNAPSHOT-2025-02-15-a #79916

@hjyamauchi

Description

@hjyamauchi

Description

The compiler crashes with this message:

checked decl cannot have error type
(accessor_decl decl_context=0x11f844848 range=[Repro.swift:2:58 - line:2:58] <anonymous @ 0x11f893798> interface_type="<Self where Self : TextContainerViewProtocol> (Self) -> () -> <<error type>>" access=internal captures=(<generic>  type=τ_0_0) get for="delegate"
  (parameter "self" decl_context=0x11f893790) result="<<error type>>" thrown_type="<null>"
  (parameter_list))

Reproduction

Reduced test Repro.swift

protocol TextContainerViewProtocol {
    var delegate: any TextContainerViewDelegate<Self>? { get set}
}

protocol TextContainerViewDelegate<View> {
    associatedtype View: TextContainerViewProtocol
}

Command line

% ~/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-03-10-a.xctoolchain/usr/bin/swiftc Repro.swift
error: compile command failed due to signal 6 (use -v to see invocation)
checked decl cannot have error type
(accessor_decl decl_context=0x14583e248 range=[Repro.swift:2:58 - line:2:58] <anonymous @ 0x14588cf98> interface_type="<Self where Self : TextContainerViewProtocol> (Self) -> () -> <<error type>>" access=internal captures=(<generic>  type=τ_0_0) get for="delegate"
  (parameter "self" decl_context=0x14588cf90) result="<<error type>>" thrown_type="<null>"
  (parameter_list))
...

Stack dump

Stack dump:
0.	Program arguments: /Users/hiroshi/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-03-09-a.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file Repro.swift -target arm64-apple-macosx15.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -color-diagnostics -empty-abi-descriptor -resource-dir /Users/hiroshi/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-03-09-a.xctoolchain/usr/lib/swift -no-auto-bridging-header-chaining -module-name Repro -in-process-plugin-server-path /Users/hiroshi/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-03-09-a.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path /Users/hiroshi/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-03-09-a.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Users/hiroshi/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2025-03-09-a.xctoolchain/usr/local/lib/swift/host/plugins -o /var/folders/ww/kxcj3hm12kd92gcwr9t3y7k40000gq/T/TemporaryDirectory.Lj8k4y/Repro-1.o
1.	Apple Swift version 6.2-dev (LLVM 527e08406d53663, Swift 911fbb6d932c543)
2.	Compiling with effective version 5.10
3.	While walking into 'TextContainerViewProtocol' (at Repro.swift:1:1)
4.	While verifying AccessorDecl getter for delegate (at Repro.swift:2:9)
5.	While verifying FuncDecl getter for delegate (at Repro.swift:2:9)
6.	While verifying AbstractFunctionDecl getter for delegate (at Repro.swift:2:9)
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x00000001062e49f0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001062e311c llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001062e5038 SignalHandler(int, __siginfo*, void*) + 296
3  libsystem_platform.dylib 0x00000001954a2de4 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000019546bf70 pthread_kill + 288
5  libsystem_c.dylib        0x0000000195378908 abort + 128
6  swift-frontend           0x0000000106360948 (anonymous namespace)::Verifier::verifyParsed(swift::AssociatedTypeDecl*) (.cold.2) + 0
7  swift-frontend           0x00000001020f3dac (anonymous namespace)::Verifier::verifyChecked(swift::ValueDecl*) + 300
8  swift-frontend           0x00000001020f4b20 (anonymous namespace)::Verifier::verifyChecked(swift::AbstractFunctionDecl*) + 856
9  swift-frontend           0x00000001020f4ce0 (anonymous namespace)::Verifier::verifyChecked(swift::FuncDecl*) + 284
10 swift-frontend           0x00000001020e7460 (anonymous namespace)::Verifier::walkToDeclPost(swift::Decl*) + 1496
11 swift-frontend           0x00000001020f59d0 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 308
12 swift-frontend           0x00000001020f8408 (anonymous namespace)::Traversal::visit(swift::Decl*) + 844
13 swift-frontend           0x00000001020f59b8 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 284
14 swift-frontend           0x00000001020f7910 swift::Pattern* llvm::function_ref<swift::Pattern* (swift::Pattern*)>::callback_fn<(anonymous namespace)::Traversal::doIt(swift::Pattern*)::'lambda'(swift::Pattern*)>(long, swift::Pattern*) + 376
15 swift-frontend           0x00000001020f6e50 swift::Pattern* (anonymous namespace)::Traversal::traverse<swift::Pattern>(swift::ASTWalker::PreWalkResult<swift::Pattern*>, llvm::function_ref<swift::Pattern* (swift::Pattern*)>, llvm::function_ref<swift::ASTWalker::PostWalkResult<swift::Pattern*> (swift::Pattern*)>) + 84
16 swift-frontend           0x00000001020f7958 swift::Pattern* llvm::function_ref<swift::Pattern* (swift::Pattern*)>::callback_fn<(anonymous namespace)::Traversal::doIt(swift::Pattern*)::'lambda'(swift::Pattern*)>(long, swift::Pattern*) + 448
17 swift-frontend           0x00000001020f6e50 swift::Pattern* (anonymous namespace)::Traversal::traverse<swift::Pattern>(swift::ASTWalker::PreWalkResult<swift::Pattern*>, llvm::function_ref<swift::Pattern* (swift::Pattern*)>, llvm::function_ref<swift::ASTWalker::PostWalkResult<swift::Pattern*> (swift::Pattern*)>) + 84
18 swift-frontend           0x00000001020f8a2c (anonymous namespace)::Traversal::visit(swift::Decl*) + 2416
19 swift-frontend           0x00000001020f59b8 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 284
20 swift-frontend           0x00000001020f8f94 (anonymous namespace)::Traversal::visitNominalTypeDecl(swift::NominalTypeDecl*) + 480
21 swift-frontend           0x00000001020f8148 (anonymous namespace)::Traversal::visit(swift::Decl*) + 140
22 swift-frontend           0x00000001020f59b8 (anonymous namespace)::Traversal::doIt(swift::Decl*) + 284
23 swift-frontend           0x00000001020f5890 swift::Decl::walk(swift::ASTWalker&) + 32
24 swift-frontend           0x00000001022a6190 swift::SourceFile::walk(swift::ASTWalker&) + 188
25 swift-frontend           0x00000001020e4874 swift::verify(swift::SourceFile&) + 96
26 swift-frontend           0x00000001023b0db4 swift::TypeCheckPrimaryFileRequest::cacheResult(std::__1::tuple<>) const + 76
27 swift-frontend           0x0000000101e78538 swift::performTypeChecking(swift::SourceFile&) + 92
28 swift-frontend           0x0000000100e605fc bool llvm::function_ref<bool (swift::SourceFile&)>::callback_fn<swift::CompilerInstance::performSema()::$_0>(long, swift::SourceFile&) + 16
29 swift-frontend           0x0000000100e57ac8 swift::CompilerInstance::forEachFileToTypeCheck(llvm::function_ref<bool (swift::SourceFile&)>) + 76
30 swift-frontend           0x0000000100e57a5c swift::CompilerInstance::performSema() + 76
31 swift-frontend           0x0000000100c2b334 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 60
32 swift-frontend           0x0000000100c20b98 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 716
33 swift-frontend           0x0000000100c203b4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 2244
34 swift-frontend           0x00000001009e2240 swift::mainEntry(int, char const**) + 3064
35 dyld                     0x00000001950ec274 start + 2840

Expected behavior

No crash but this error

Repro.swift:2:23: error: use of protocol 'TextContainerViewDelegate<Self>' as a type must be written 'any TextContainerViewDelegate<Self>'
1 | protocol TextContainerViewProtocol {
2 |     var delegate: any TextContainerViewDelegate<Self>? { get set}
  |                       `- error: use of protocol 'TextContainerViewDelegate<Self>' as a type must be written 'any TextContainerViewDelegate<Self>'
3 | }
4 | 

Environment

The latest macos development snapshot build https://download.swift.org/development/xcode/swift-DEVELOPMENT-SNAPSHOT-2025-03-10-a/swift-DEVELOPMENT-SNAPSHOT-2025-03-10-a-osx.pkg

A quick bisecting shows that this crash started with the build swift-DEVELOPMENT-SNAPSHOT-2025-02-15-a and doesn't reproduce with swift-DEVELOPMENT-SNAPSHOT-2025-02-14-a

Additional information

No response

Metadata

Metadata

Assignees

Labels

TypeResolverbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconstrained existentialsFeature → existentials: constrained existentials such as 'any Collection<Int>'crashBug: A crash, i.e., an abnormal termination of softwareexistentialsFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesswift 6.1swift 6.2type checkerArea → compiler: Semantic analysis

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions