Open
Description
Description
Swift code that follows a pattern in which an variable representing AnyClass
is initialized with .init()
crashes the compiler.
Steps to reproduce
- Type
swift repl
in the Terminal to enter Swift repl - Paste in the following code:
import Foundation
func crashy() -> NSObject {
let aClass: AnyClass = NSObject.self
return aClass.init() as! NSObject
}
- Press return
Expected behavior
The code should compile or should generate compiler warnings and/or errors.

Environment
swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100)
Target: arm64-apple-macosx13.0
Xcode 14.3
Build version 14E222b
- Xcode version info
- Deployment target:
Metadata
Metadata
Assignees
Labels
LLVM IR generationA deviation from expected or documented behavior. Also: expected but undesirable behavior.Feature: explicit casting (is, as, as? and as!)The Swift compiler itselfBug: A crash, i.e., an abnormal termination of softwareFeature → types: MetatypesFeature: Interoperability with Objective-C