Skip to content

Instantly share code, notes, and snippets.

@mpurland
Last active December 28, 2015 00:19
Show Gist options
  • Save mpurland/ab80d471729d7d7b1ce7 to your computer and use it in GitHub Desktop.
Save mpurland/ab80d471729d7d7b1ce7 to your computer and use it in GitHub Desktop.
Example to cause the Swift compiler to go into an infinite loop
import Foundation
typealias Mask = UInt64
enum Category: UInt8 {
case A
case B
case C
case D
case E
case F
case G
case H
}
extension Mask {
init(_ category: Category) {
self = UInt64(1) << UInt64(category.rawValue)
}
}
extension Mask {
static let dictionary: [Category: Mask] = [
.A: Mask(.A) | Mask(.B) | Mask(.C) | Mask(.D) | Mask(.E) | Mask(.F) | Mask(.G) | Mask(.H),
// Comment the line below to have it successfully compile. with these two lines it fails to compile
.B: Mask(.A) | Mask(.B) | Mask(.C) | Mask(.D) | Mask(.E) | Mask(.F) | Mask(.G) | Mask(.H),
]
}
@mpurland
Copy link
Author

I'm using Xcode 7.2

@mpurland
Copy link
Author

This is a much simpler example of it happening:

import Foundation

typealias Mask = UInt64

enum Category: UInt8 {
    case A
    case B
    case C
    case D
    case E
    case F
    case G
    case H
}

extension Mask {
    static let dictionary: [Category: Mask] = [
        .A: Mask(.A) | Mask(.B) | Mask(.C) | Mask(.D) | Mask(.E) | Mask(.F) | Mask(.G) | Mask(.H)
    ]
}

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