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

[SR-7066] Compiler does not warn on duplicate keys for dictionary literals #49614

swift-ci opened this issue Feb 23, 2018 · 3 comments


Copy link

swift-ci commented Feb 23, 2018

Previous ID SR-7066
Radar None
Original Reporter erica (JIRA User)
Type Bug

Version 9.2 (9C40b)

Additional Detail from JIRA
Votes 0
Component/s Compiler, Standard Library
Labels Bug
Assignee None
Priority Medium

md5: 55fa9f54aa6d8465d1df9a15dab092cf

Issue Description:

let insets: UIEdgeInsets = [.left: 4, .right: 4, .left: 8]

The compiler accepts this without warning. I think it probably should warn/error if the literal can be checked at compile time.

Copy link
Collaborator Author

swift-ci commented Feb 23, 2018

Comment by erica sadun (JIRA)

The problem may be with the name, as a dictionary literal is initialized as an ordered array of tuples (thanks Stephen Celis). Maybe it should be a "tuple sequence literal".

See Also:

Copy link

belkadan commented Feb 26, 2018

Yeah, I think this behavior is deliberate, and it'd also be hard to do for non-literal types. (We'd need some kind of notion of structurally-equivalent expressions, which is not unreasonable but isn't something the compiler currently has.). @moiseev, @airspeedswift, thoughts?

Copy link
Collaborator Author

swift-ci commented Feb 26, 2018

Comment by erica sadun (JIRA)

There are really two questions here:

  1. Is including the same key in a dictionary literal a bug, and if so, can it be caught?

  2. If the problem is in the name, which promises a dictionary literal (which this isn't due to key duplication), can it be solved by renaming to a more accurate `DictionaryStyleLiteral` or `DictionaryStyleTupleSequence` or `DictionaryStyleLiteralInitializable` sort of thing?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants