Xcode 16 type cast to protocol with constrained associated type

Is this code legal?
The code compiles successfully on xcode 15, but the compiler crashes on xcode 16

let row:Any = TestRow()

if let row = row as? (any EntityRow) {
    print(row.entity.guid)
}

class TestEntity:Entity{
    var guid: UUID = UUID()
}

class Row{
    var height:CGFloat = 0;
}

protocol Entity{
    var guid:UUID{get}
}

protocol EntityRow:AnyObject {
    associatedtype E:Entity;
    var entity:E {get set}
}

class TestRow:Row,EntityRow{
    var entity:TestEntity = .init()
}

Fundamentally the compiler shouldn't crash, so regardless of whether or not the code is legal this should be reported as a bug. I can reproduce the problem, so I've filed Github Issue #76400. Thank-you for bringing this to our attention, and thanks for the reduced test case.

I think this is legal Swift code, I might add.

1 Like

thank you very much