Skip to content

Compiler crash when compiling code that initializes AnyClass #66089

Open
@danielpunkass

Description

@danielpunkass

Description

Swift code that follows a pattern in which an variable representing AnyClass is initialized with .init() crashes the compiler.

Steps to reproduce

  1. Type swift repl in the Terminal to enter Swift repl
  2. Paste in the following code:
import Foundation
func crashy() -> NSObject {
	let aClass: AnyClass = NSObject.self
	return aClass.init() as! NSObject
}
  1. Press return

Expected behavior

The code should compile or should generate compiler warnings and/or errors.

image

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

No one assigned

    Labels

    IRGenLLVM IR generationbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.castingFeature: explicit casting (is, as, as? and as!)compilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwaremetatypesFeature → types: Metatypesobjective-c interopFeature: Interoperability with Objective-Cswift 5.8

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions