typealias for Generic in Generic


#1

Hello.
I stumbled on ambiguous behaviour of compiler. Is not allowed explicitly indicate type in Generic typealias.

struct Сarriage<T> {
let g = [ T ]()
}

struct Coma<T> {
typealias R = Сarriage < T >
let m = R ()
let d = R < String >() \\ error: cannot specialize non-generic type 'Сarriage<T>'
var b = Сarriage < String >()
mutating func work() {
m .g.append(<#T##newElement: T##T#>) \\ what I can write here?
b . g . append ( "Z" )
}
}

···

--
Седых Александр


(Adrian Zubarev) #2

R is a non generic type, because the generic part is set to T, that’s why R() works.

Otherwise you could create typealias Q<NameThatIsNot_T> = Сarriage<NameThatIsNot_T> and use it like this Q<String>()

···

--
Adrian Zubarev
Sent with Airmail

Am 4. April 2017 um 19:25:45, Седых Александр via swift-users (swift-users@swift.org) schrieb:

Hello.
I stumbled on ambiguous behaviour of compiler. Is not allowed explicitly indicate type in Generic typealias.

struct Сarriage<T> {
let g = [T]()
}

struct Coma<T> {
typealias R = Сarriage<T>
let m = R()
let d = R<String>() \\ error: cannot specialize non-generic type 'Сarriage<T>'
var b = Сarriage<String>()
mutatingfunc work() {
m.g.append(<#T##newElement: T##T#>) \\ what I can write here?
b.g.append("Z")
}
}

--
Седых Александр _______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users