-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed as duplicate of#44398
Closed as duplicate of#44398
Copy link
Labels
TypeResolverbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfexpressionsFeature: expressionsFeature: expressionsgenericsFeature: generic declarations and typesFeature: generic declarations and typesswift 6.0swift evolution proposal neededFlag → feature: A feature that warrants a Swift evolution proposalFlag → feature: A feature that warrants a Swift evolution proposaltype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysistype inferenceFeature: type inferenceFeature: type inferenceunexpected errorBug: Unexpected errorBug: Unexpected error
Description
| Previous ID | SR-514 |
| Radar | None |
| Original Reporter | mschumacher (JIRA User) |
| Type | Bug |
| Status | Resolved |
| Resolution | Duplicate |
Additional Detail from JIRA
| Votes | 0 |
| Component/s | Compiler |
| Labels | Bug, TypeChecker |
| Assignee | None |
| Priority | Medium |
md5: 25c05faa51facf7575dd488e4683f95d
duplicates:
Issue Description:
Example:
struct Wrapper<T> {
let value: T
func map<R>(closure: T -> R) -> Wrapper<R> {
return Wrapper(value: closure(value))
}
}This code produces the error:
Cannot invoke initializer for type 'Wrapper<T>' with an argument list of type '(value: R)'
Though it makes sense that this error occurs, since within Wrapper's implementation, T is bound to a concrete type, this shouldn't happen. Expected behavior is that Wrapper<T> can be constructed with any type.
It's maybe worth noting that there is a work-around:
protocol WrapperType {
typealias T
var value: T { get }
}
extension WrapperType {
func map<R>(closure: Self.T -> R) -> Wrapper<R> {
return Wrapper(value: closure(self.value))
}
}
struct Wrapper<T>: WrapperType {
let value: T
}But it's verbose and unintuitive.
Metadata
Metadata
Assignees
Labels
TypeResolverbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfexpressionsFeature: expressionsFeature: expressionsgenericsFeature: generic declarations and typesFeature: generic declarations and typesswift 6.0swift evolution proposal neededFlag → feature: A feature that warrants a Swift evolution proposalFlag → feature: A feature that warrants a Swift evolution proposaltype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysistype inferenceFeature: type inferenceFeature: type inferenceunexpected errorBug: Unexpected errorBug: Unexpected error