[swift-evolution] Problems with generics - should be fixed for Xcode 9?

Douglas Gregor dgregor at apple.com
Sun Sep 17 23:23:03 CDT 2017



Sent from my iPhone

> On Sep 16, 2017, at 6:32 AM, Joanna Carter via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Greetings
> 
> Old chestnut, sort of partially solved but still problems.
> 
> Now we can nest types in generic types, what I want is :
> 
> class Event<typeT>
> {
>  class Args
>  {
>    public static let empty = Args() // error : Static stored properties not supported in generic types
>  }
> }
> 
> But the static let is not directly in the generic class.

It's still generic, though, because of the outer generic class, so there is a different static var for each specialization. For example, the following assert would fail:

  assert(Event<Int>.Args.empty === Event<String>.Args.empty)



> 
> So, I end up doing another convoluted workaround in the shape of :
> 
> class Event<typeT>
> {
>  class Args
>  {
>    public static var empty: Args
>    {
>      return Args()
>    }
>  }
> }
> 
> The main difference is that I have to create a new instance on every call to Args.empty instead of returning the same one.
> 
> Is this an oversight or as intended, with the hope of fixing it in a future version

I'd say we consider it a bug. 

  - Doug

> 
> Joanna
> 
> --
> Joanna Carter
> Carter Consulting
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution


More information about the swift-evolution mailing list