What kind of magic behavior is this?

There are long standing compiler bugs in this area.

For example the following (AFAICS clearly invalid) program still compiles with Swift 4.2 (haven't checked 5.0):

struct X<T> {
    var a : A
}
extension X where T == Never {
    typealias A = Int
}
let x = X<Int>(a: 123)