Generic typealias inside generic type


(Vladimir) #1

Please consider this code:

struct Foo<T> {
     typealias Group<Key,Value> = (key:Key, group:[Value])

     func bar<U,V>(u: U, v: V) -> Foo<Group<U,V>> {
         return Foo<Group<U,V>>()
     }
}

It will not compile:
cannot specialize non-generic type '(key: Key, group: [Value])'

But this will work as expected:

typealias Group<Key,Value> = (key:Key, group:[Value])

struct Foo<T> {
     func bar<U,V>(u: U, v: V) -> Foo<Group<U,V>> {
         return Foo<Group<U,V>>()
     }
}

Shouldn't we be able to work with Group typealias inside Foo<T> without problems as it has no any relationship to generic type T ? Or I'm missing something?


(Chris Lattner) #2

Yes, this should work, it is a bug in the compiler.

-Chris

···

On Jun 17, 2016, at 11:06 AM, Vladimir.S via swift-evolution <swift-evolution@swift.org> wrote:

Please consider this code:

struct Foo<T> {
   typealias Group<Key,Value> = (key:Key, group:[Value])

   func bar<U,V>(u: U, v: V) -> Foo<Group<U,V>> {
       return Foo<Group<U,V>>()
   }
}

It will not compile:
cannot specialize non-generic type '(key: Key, group: [Value])'

But this will work as expected:

typealias Group<Key,Value> = (key:Key, group:[Value])

struct Foo<T> {
   func bar<U,V>(u: U, v: V) -> Foo<Group<U,V>> {
       return Foo<Group<U,V>>()
   }
}

Shouldn't we be able to work with Group typealias inside Foo<T> without problems as it has no any relationship to generic type T ? Or I'm missing something?


(Vladimir) #3

Please consider this code:

struct Foo<T> {
   typealias Group<Key,Value> = (key:Key, group:[Value])

   func bar<U,V>(u: U, v: V) -> Foo<Group<U,V>> {
       return Foo<Group<U,V>>()
   }
}

It will not compile:
cannot specialize non-generic type '(key: Key, group: [Value])'

But this will work as expected:

typealias Group<Key,Value> = (key:Key, group:[Value])

struct Foo<T> {
   func bar<U,V>(u: U, v: V) -> Foo<Group<U,V>> {
       return Foo<Group<U,V>>()
   }
}

Shouldn't we be able to work with Group typealias inside Foo<T> without problems as it has no any relationship to generic type T ? Or I'm missing something?

Yes, this should work, it is a bug in the compiler.

Reported. SR-1832

···

On 19.06.2016 7:52, Chris Lattner wrote:

On Jun 17, 2016, at 11:06 AM, Vladimir.S via swift-evolution <swift-evolution@swift.org> wrote:

-Chris


(Vladimir) #4

Please consider this code:

struct Foo<T> {
   typealias Group<Key,Value> = (key:Key, group:[Value])

   func bar<U,V>(u: U, v: V) -> Foo<Group<U,V>> {
       return Foo<Group<U,V>>()
   }
}

It will not compile:
cannot specialize non-generic type '(key: Key, group: [Value])'

But this will work as expected:

typealias Group<Key,Value> = (key:Key, group:[Value])

struct Foo<T> {
   func bar<U,V>(u: U, v: V) -> Foo<Group<U,V>> {
       return Foo<Group<U,V>>()
   }
}

Shouldn't we be able to work with Group typealias inside Foo<T> without problems as it has no any relationship to generic type T ? Or I'm missing something?

Yes, this should work, it is a bug in the compiler.

Btw, should we be able to refer such nested type (outside the Foo declaration) just as Foo.Group<K,V> i.e. without providing generic type for Foo like Foo<Int>.Group<K,V> ?

···

On 19.06.2016 7:52, Chris Lattner wrote:

On Jun 17, 2016, at 11:06 AM, Vladimir.S via swift-evolution <swift-evolution@swift.org> wrote:

-Chris