Skip to content

Missing warning "has duplicate entries for integer literal key" when literal keys are produced by a macro #77318

Open
@stefanspringer1

Description

@stefanspringer1

Description

When using a literal dictionary with literal keys which are produced by a macro, no warning is given for duplicate keys.

Reproduction

The following code uses the macro #codepointForEntity from https://github.com/stefanspringer1/CodepointForEntityMacro.git:

let map: [UInt32:String] = [
            #codepointForEntity("½"): " 1 / 2 ",
            #codepointForEntity("½"): " 1 / 2 ",
            #codepointForEntity("⅓"): " 1 / 3 ",
            #codepointForEntity("¼"): " 1 / 4 ",
            #codepointForEntity("¾"): " 3 / 4 ",
            #codepointForEntity("⅛"): " 1 / 8 ",
            #codepointForEntity("⅜"): " 3 / 8 ",
            #codepointForEntity("⅝"): " 5 / 8 ",
            #codepointForEntity("⅞"): " 7 / 8 ",
        ]

No warning is given, but the execution results in a Trace/BPT trap: 5 error.

The macro produces the following code with a duplicate key:

let map: [UInt32:String] = [
            0xBD: " 1 / 2 ",
            0xBD: " 1 / 2 ",
            0x2153: " 1 / 3 ",
            0xBC: " 1 / 4 ",
            0xBE: " 3 / 4 ",
            0x215B: " 1 / 8 ",
            0x215C: " 3 / 8 ",
            0x215D: " 5 / 8 ",
            0x215E: " 7 / 8 ",
        ]

If this code is directly used (without the macro), the following warning is given:

Dictionary literal of type '[UInt32 : String]' has duplicate entries for integer literal key '0xBD'

Expected behavior

It would be very convenient to have the warning also when the macro is used.

Environment

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx14.0

Additional information

Note that for duplicate entries of a dictionary, there also is the issue #78595 "Dictionary literal has duplicate entries" should be an error not warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.swift macroFeature → declarations: Swift `macro` declarations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions