-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
Labels
IRGenLLVM IR generationLLVM IR generationbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.castingFeature: explicit casting (is, as, as? and as!)Feature: explicit casting (is, as, as? and as!)compilerThe Swift compiler itselfThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareBug: A crash, i.e., an abnormal termination of softwaremetatypesFeature → types: MetatypesFeature → types: Metatypesobjective-c interopFeature: Interoperability with Objective-CFeature: Interoperability with Objective-Cswift 5.8
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
IRGenLLVM IR generationLLVM IR generationbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.castingFeature: explicit casting (is, as, as? and as!)Feature: explicit casting (is, as, as? and as!)compilerThe Swift compiler itselfThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareBug: A crash, i.e., an abnormal termination of softwaremetatypesFeature → types: MetatypesFeature → types: Metatypesobjective-c interopFeature: Interoperability with Objective-CFeature: Interoperability with Objective-Cswift 5.8