-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Description
| Previous ID | SR-8401 |
| Radar | None |
| Original Reporter | @allenhumphreys |
| Type | Bug |
| Status | Resolved |
| Resolution | Duplicate |
Environment
Swift 4.1 Xcode 9.4.1
Additional Detail from JIRA
| Votes | 0 |
| Component/s | Compiler |
| Labels | Bug |
| Assignee | None |
| Priority | Medium |
md5: cd7c569a6c30091ff8deac1ccd6486bd
duplicates:
Issue Description:
I'm not sure if this is a bug, but it kind of threw me for a loop so I thought I'd pose the question.
class CallWrapper<T, U: Decodable> {
static func function() -> CallWrapper<Float, Float> {
return CallWrapper() // Compiler Error: Cannot convert return expression of type 'SubCall<T>' to return type 'SubCall<Float>'
// Fixit: Insert ' as! SubCall<Float>'
}
typealias TypeAlias<V, W: Decodable> = CallWrapper<V, W>
static func function2() -> TypeAlias<Float, Float> {
return TypeAlias()
}
}With function, I kind of expect type inference to pick up the return type of the function and use it for the initializer. But I understand kind of why it maybe shouldn't or can't because the type of the initializer in the static context is determined at the call site, i.e. CallWrapper<Int, Int>.function().
Things got strange for me, though, when I made a type alias, as in function2, where I was able to use type inference to only specify the complete type as the return of the function. My goal is convenience because in my case the types are pretty long and using the inference makes it easy to change the code.
I don't understand why type inference could work with the alias but not with the bare type, and was curious if one or the other is a bug.