Compiler crashes when using protocols with associated type

Hello everyone,
I have a project in which I created several protocols that have an associatedType, implemented by some generic classes. In particular, there is a protocol with a method requirement and an associatedType, and this type conforms to another protocol that has another associatedType. When I try to build the project, the compiler crashes, giving a Segmentation fault error when trying to build the method I mentioned before but without explaining the reason.
Of course the code is much more complex than this, but I managed to reproduce the issue in a short playground:

protocol C {
  associatedtype Type1
}

protocol B {
  associatedtype Type2: C
  
  func register()
}

extension B {
  func register() {
    print("Hello")
  }
}

class MyClass: C {
  typealias Type1 = Int
}

class MyGeneric<T>: B where T: C {
  typealias Type2 = T
}

let c = MyGeneric<MyClass>()

c.register()

I don't know what should be the issue in this code, but at least I think the compiler should report it.

The compiler can't report it because it crashes. So you have uncovered a bug in the compiler. :tada:

In that case please always file a bug at https://bugs.swift.org/.
Especially since you have done a fantastic job of distilling the problem down! That'll help really a lot.

1 Like

Thanks, I'll report the bug.

1 Like