I think problem has to do with targetType being null over here https://github.com/apple/swift/blob/78f3017436dbbfe380b69b09a2d02937524ab076/stdlib/public/runtime/Casting.cpp#L1127
It seem like code expect targetType to be always not-null - A NPE check "fixes" the issue but I was wondering if that is the right thing to do. What would be expected targetType in this case?
I think the target type should be AnyObject & CustomStringConvertible, which should end up in the _dynamicCastToExistential function in that file rather than the one you called out. The code doesn't seem to crash on macOS for me (using master or 4.2), so maybe it's a problem with the non-SWIFT_OBJC_INTEROP parts of the code?
Interestingly, wrapping it with print works. Wonder why that would be the case? @millenomi, any pointers?
allToAll(5, (AnyObject & CustomStringConvertible).self) //This segfaults on Linux, but ...
print(allToAll(5, (AnyObject & CustomStringConvertible).self)) // .. this works on Linux