Skip to content

Compiler allows unlimited use of unsafe keyword #82315

Open
@natecook1000

Description

@natecook1000

Description

While I appreciate the opportunity for histrionics, we should probably cap the number of times you're allowed to write the unsafe keyword at 1. The code below compiles for me using the June 12 nightly toolchain.

Reproduction

func superDuperUnsafe(_ bytes: UnsafeRawBufferPointer) {
  let byte = unsafe unsafe unsafe unsafe unsafe unsafe unsafe bytes.first ?? 0
  print(byte)
}

Expected behavior

A compiler error on the second (and following) use of unsafe

Environment

Apple Swift version 6.2-dev (LLVM d266fd9f80a7945, Swift 665515c)
Target: arm64-apple-macosx26.0
Build config: +assertions

Additional information

rdar://153672668

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.memory safetyFeature: memory safety

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions