Skip to content

Instantly share code, notes, and snippets.

@indragiek
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indragiek/9c4bdaff950515e0a95b to your computer and use it in GitHub Desktop.
Save indragiek/9c4bdaff950515e0a95b to your computer and use it in GitHub Desktop.
This code doesn't compile (Xcode 6.1.1, Swift 1.1)
public protocol TableViewSectionType {
typealias ItemCollection: CollectionType
}
public protocol TableViewCellFactoryType {
typealias Item
}
public final class TableViewDataSource<
SectionCollection: CollectionType,
Factory: TableViewCellFactoryType
where
SectionCollection.Generator.Element: TableViewSectionType,
SectionCollection.Generator.Element.ItemCollection.Generator.Element == Factory.Item // Changing this to a concrete type like Int fixes it
> {
}
@indragiek
Copy link
Author

This code doesn't compile under Swift 1.1:

Command failed due to signal: Segmentation fault: 11
...
1.  While emitting IR for source file /Users/Karunaratne/Desktop/sandbox/sandbox/generics.swift
2.  While emitting class metadata for 'TableViewDataSource' at /Users/Karunaratne/Desktop/sandbox/sandbox/generics.swift:19:14

If I change this constraint:

SectionCollection.Generator.Element.ItemCollection.Generator.Element == Factory.Item

to use a concrete type like Int rather than Factory.Item, the code compiles successfully.

Compiler bug or am I doing something wrong?

@indragiek
Copy link
Author

Swapping the order of SectionCollection and Factory in the generic type parameter list seems to have fixed it. Probably a bug, then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment