Swift-frontend crash switching over (any Error)?

Here's the code:

var error: Error?
// ... something which may or may not set error ...

switch error {
case AFError.explicitlyCancelled:
    // Task was cancelled, don't continue
    return
case let e?:
    debugPrint(e)
    self.error = e
default:
    break
}

For some reason, this switch statement causes swift-frontend to blow up:

swift-frontend: /home/build-user/llvm-project/llvm/include/llvm/Support/Casting.h:578: decltype(auto) llvm::cast(From *) [To = swift::ExistentialArchetypeType, From = swift::TypeBase]: Assertion `isa(Val) && "cast() argument of incompatible type!"' failed.

Restructuring this so the switch is not over an optional works fine, i.e:

if let error {
    switch error {
    case AFError.explicitlyCancelled:
        // Task was cancelled, don't continue
        return
    default:
        debugPrint(error)
        self.error = error
    }
}

Is this a known issue, or should I file one?

i've made some assumptions about the rest of your code, but it doesn't seem to compile for me. i get an error like:

error: pattern of type 'AFError' cannot match '(any Error)?'

The project is public here: GitHub - bbrk24/weather-app Replace the if let on line 105 of Sources/WeatherApp/ViewModels/ForecastViewModel.swift with the switch from the offending code to reproduce the crash. It’s possible there’s more relevant context I’m missing.

Also in case it's relevant, I'm on Ubuntu 24.04 with this Swift version:

Swift version 6.3-dev (LLVM 2bc32d2793f525d, Swift f1a704763ffd2c8)
Target: x86_64-unknown-linux-gnu
Build config: +assertions

Could you provide a reproducer in Godbolt?