Skip to content

Instantly share code, notes, and snippets.

@rileytestut
Created June 23, 2016 18:35
Show Gist options
  • Save rileytestut/3f6a1384798a2984260c2e088fe84a06 to your computer and use it in GitHub Desktop.
Save rileytestut/3f6a1384798a2984260c2e088fe84a06 to your computer and use it in GitHub Desktop.
Type Inference Crash
import Foundation
import UIKit
// If defined here in the same module, no issue
// However, if defined in a separate module + used, will cause compiler crash
// public typealias GenericResult<T> = Result<T, NSError>
func testFunction<T>(withCompletion completion: (Result<T, NSError>) -> Void)
{
// Do Stuff
}
// This works
testFunction { (result: Result<Data, NSError>) in }
// This crashes the compiler if GenericResult<T> is defined in another module :(
testFunction { (result: GenericResult<Data>) in }
print("Hello World")
// NOTE: This must be compiled in a separate module for the crash to manifest
import Foundation
public enum Result<T, U: ErrorProtocol>
{
case success(T)
case failure(U)
}
public typealias GenericResult<T> = Result<T, NSError>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment