Skip to content

Constants of type Never used in switch statements do not trigger error for use of uninitialized constant, leading to runtime crash #74478

Open
@schuelermine

Description

@schuelermine

Description

When a constant is declared with type Never and subsequently used as the subject of a switch statement, the compiler fails to diagnose the use of an uninitialized constant, leading to a runtime crash.

Reproduction

let x: Never
switch x { }

I will provide the crash message shortly; at the moment, I am not at my computer.

Expected behavior

The compiler should produce an error.

Environment

I believe it is 5.10.1, but I am not sure as I am not at my computer. I downloaded the release about a week ago. I will report the version as soon as I am back at my computer.

I was running Swift in an Ubuntu 24.04 container. Swift was installed to /opt/swift.

Additional information

I was informed this is not intentional in this thread on the forum.

Metadata

Metadata

Assignees

Labels

NeverArea → standard library: The `Never` typeSILGenArea → compiler: The SIL generation stageaccepts invalidBug: Accepts invalidbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdefinite initializationArea → compiler → SIL: Definite initializationlet & varFeature: constant and variable declarationsstatementsFeature: statementsswift 6.0switchFeature → statements: 'switch' statements

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions