Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stefanspringer1 opened this issue Oct 31, 2024 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. swift macro Feature → declarations: Swift `macro` declarations

Comments

@stefanspringer1
Copy link

stefanspringer1 commented Oct 31, 2024

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.

@stefanspringer1 stefanspringer1 added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Oct 31, 2024
@hborla hborla added swift macro Feature → declarations: Swift `macro` declarations and removed triage needed This issue needs more specific labels labels Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. swift macro Feature → declarations: Swift `macro` declarations
Projects
None yet
Development

No branches or pull requests

2 participants