Swift compiler crashes by generics / missing conformance

struct Foo<T> {}
struct Bar {}

let foo = Foo<Bar>()
let foos: Set<Foo> = [foo]

trying to run this crashes the compiler.

the code snippet above is an attempt from me to get a minimal reproduction of the code that causes the crash. my original code is structured like this (still super simplified, took me a good hour to find the problem):

protocol Game {}
struct Card<Game> {}

struct Blackjack: Game {}

let card = Card<Blackjack>()
let cards: Set<Card> = [card]

where i had forgot to add a Hashable conformance to Card.

2 Likes

The compiler should not be crashing, but here is the solution:

struct Foo<T> { }
struct Bar: Hashable { }
extension Foo: Hashable & Equatable where T: Hashable { }

let foo = Foo<Bar>()
let foos: Set = [foo]
protocol Game { }
struct Card<Game: ModuleName.Game> { }
extension Card: Hashable & Equatable where Game: Hashable { }
struct Blackjack: Game & Hashable { }

let card = Card<Blackjack>()
let cards: Set = [card]
1 Like

seems to be a recently discovered compiler bug that appears to have been sitting there since swift 5.5:

1 Like