-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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.triage neededThis issue needs more specific labelsThis issue needs more specific labels
Description
Description
When using typed throws syntax in a protocol method without an explicit return type, the Swift compiler fails to resolve the generic type parameter. When compiling it reports cannot find type 'E' in scope
even though E
is properly declared as a generic parameter.
Reproduction
The issue arises in the Stmt
protocol.
protocol StmtVisitor<ErrorType> {
associatedtype ErrorType: Error
func visit(_ expression: Expression) throws(ErrorType)
func visit(_ print: Print) throws(ErrorType)
}
protocol Stmt {
func accept<E: Error>(_ visitor: any StmtVisitor<E>) throws(E)
}
Expected behavior
The code should compile successfully with the return type implicitly being Void
Environment
Swift version 6.1.2 (swift-6.1.2-RELEASE)
Target: x86_64-unknown-linux-gnu
Arch Linux
Additional information
Workaround
Explicitly set the return type of the protocol method as Void
.
protocol Stmt {
func accept<E: Error>(_ visitor: any StmtVisitor<E>) throws(E) -> Void
}
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.triage neededThis issue needs more specific labelsThis issue needs more specific labels