Skip to content

Commit

Permalink
Fix compiler failure in Xcode 11 (#22)
Browse files Browse the repository at this point in the history
* Fix compiler failure in Xcode 11

For some unknown reason (at least to me) the `subscript(position:)`
extension on `MutableCollection` where `Index == Int` was causing the
compilation to fail with a weird `DESERIALIZATION FAILURE` error,
as mentioned on #15.

Updating the `subscript` to use `C.Index` instead of `Int` appears to
make the compiler happy and successfully compile the project. My
suspicion is that it somehow enables it to disambiguate between the
multiple `subscript` implementations, but it's pure speculation 馃敭.

On our tests this seems to have fixed the issue, and since it's an
equivalent definition of the subscript (even though more "precise"
from a generics POV), it should cause no side effects.

Fixes #15. 馃帀

* Make `NonEmpty` conform to `Collection` in type declaration

Apparently by defining `NonEmpty` as conforming to `Collection` right
away in its declaration (instead of in an extension), the compilation
failure seems to be fixed.

Even when performing a clean build, the target now successfully
compiles. 馃帀

Not sure about the actual cause for this, but this definitely seems
like a compiler bug (file ordering / dependency, perhaps?).
  • Loading branch information
p4checo committed Jan 30, 2020
1 parent 51391d6 commit 1b33a67
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/NonEmpty/NonEmpty+Collection.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
extension NonEmpty: Collection {
extension NonEmpty {
public enum Index: Comparable {
case head
case tail(C.Index)
Expand Down
2 changes: 1 addition & 1 deletion Sources/NonEmpty/NonEmpty+MutableCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension NonEmpty: MutableCollection where C: MutableCollection {
}

extension NonEmpty where C: MutableCollection, C.Index == Int {
public subscript(position: Int) -> Element {
public subscript(position: C.Index) -> Element {
get {
return self[position == 0 ? .head : .tail(self.tail.startIndex + position - 1)]
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/NonEmpty/NonEmpty.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public struct NonEmpty<C: Collection> {
public struct NonEmpty<C: Collection>: Collection {
public typealias Element = C.Element

public internal(set) var head: Element
Expand Down

0 comments on commit 1b33a67

Please sign in to comment.