A snippet that crashes the compiler

The following code snippet crashes the compiler, which in this case is Swift 5.5 release on Linux Ubuntu 20.04.

I figure this probably needs to be logged as a bug somewhere, but I thought I would seek guidance here on the forums first. A few details plus the crash log follow below.

class A {
    open func Foo( f : @escaping (Optional<A>) throws -> Void) throws -> A {

class B<T> : A {
    open override func Foo( f : @escaping (B<T>?) throws -> Void) throws -> A {

Obviously the functions needs to return a value or throw, but that doesn't affect the crash-or-not, so I've omitted that for brevity.

Renaming B.Foo to Foo2 (and remove the override keyword) avoids the crash.

Removing the question mark in the declaration of B.Foo avoids the crash.

Simply removing the override keyword yields the compiler error I would expect: "error: overriding declaration requires an 'override' keyword"

I'm not actually sure what the compiler should do with this snippet, except I assume it shouldn't crash. Is it valid Swift?

Crash output:

swift-frontend: /home/build-user/swift/lib/SIL/IR/SILFunctionType.cpp:1297: swift::CanType (anonymous namespace)::SubstFunctionTypeCollector::getSubstitutedInterfaceType(swift::Lowering::AbstractionPattern, swift::CanType): Assertion `!substType->hasTypeParameter() && !substType->hasArchetype()' failed.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.      Program arguments: /home/eric/swift-5.5-RELEASE-ubuntu20.04/usr/bin/swift-frontend -frontend -c -primary-file /home/eric/dev/crash/Sources/crash/crash.swift -emit-module-path /home/eric/dev/crash/.build/x86_64-unknown-linux-gnu/debug/crash.build/crash~partial.swiftmodule -emit-module-doc-path /home/eric/dev/crash/.build/x86_64-unknown-linux-gnu/debug/crash.build/crash~partial.swiftdoc -emit-module-source-info-path /home/eric/dev/crash/.build/x86_64-unknown-linux-gnu/debug/crash.build/crash~partial.swiftsourceinfo -emit-dependencies-path /home/eric/dev/crash/.build/x86_64-unknown-linux-gnu/debug/crash.build/crash.d -emit-reference-dependencies-path /home/eric/dev/crash/.build/x86_64-unknown-linux-gnu/debug/crash.build/crash.swiftdeps -target x86_64-unknown-linux-gnu -disable-objc-interop -I /home/eric/dev/crash/.build/x86_64-unknown-linux-gnu/debug -color-diagnostics -enable-testing -g -module-cache-path /home/eric/dev/crash/.build/x86_64-unknown-linux-gnu/debug/ModuleCache -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /home/eric/swift-5.5-RELEASE-ubuntu20.04/usr/bin/swift-driver -resource-dir /home/eric/swift-5.5-RELEASE-ubuntu20.04/usr/lib/swift -enable-anonymous-context-mangled-names -module-name crash -parse-as-library -o /home/eric/dev/crash/.build/x86_64-unknown-linux-gnu/debug/crash.build/crash.swift.o -index-store-path /home/eric/dev/crash/.build/x86_64-unknown-linux-gnu/debug/index/store -index-system-modules
1.      Swift version 5.5 (swift-5.5-RELEASE)
3.      While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "/home/eric/dev/crash/Sources/crash/crash.swift")
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):

Er, it looks like I may have re-discovered the same bug that I already reported a few months ago:


Terms of Service

Privacy Policy

Cookie Policy