-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Closed
Copy link
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwareBug: A crash, i.e., an abnormal termination of softwaretyped throwsFeature → error handling → throws & rethrows: Typed throwsFeature → error handling → throws & rethrows: Typed throws
Description
Description
I was trying to add strong error typing (the (UnwrapError) part) to this. It sadly didn't work.
extension Optional {
/// Represents that an `Optional` was `nil`.
public struct UnwrapError: Swift.Error & Equatable {
public init() { }
}
@inlinable public var wrappedValue: Wrapped {
get throws(UnwrapError) {
switch self {
case let wrapped?: return wrapped
case nil: throw UnwrapError()
}
}
}
}Reproduction
This all compiles fine.
struct GenericError<T>: Error {
init() { }
}
struct S<T> {
var property: Void {
get throws(GenericError<Void>) { }
}
func method() throws(GenericError<Void>) { }
}But change the <Voids> to <T>s, and the compiler crashes.
struct S<T> {
var property: Void {
get throws(GenericError<T>) { }
}
func method() throws(GenericError<T>) { }
}Stack dump
Command SwiftCompile failed with a nonzero exit code
Expected behavior
throws() supports all errors that can be thrown.
Environment
swift-driver version: 1.109.2 Apple Swift version 6.0 (swiftlang-6.0.0.3.300 clang-1600.0.20.10)
Target: arm64-apple-macosx14.0
Additional information
No response
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwareBug: A crash, i.e., an abnormal termination of softwaretyped throwsFeature → error handling → throws & rethrows: Typed throwsFeature → error handling → throws & rethrows: Typed throws