-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Can't use an expression as a dict key? #5231
Comments
This is a known limitation and it's documented too: IIRC this was done because it was easier to implement at the time. I'm sure we'd be happy to accept patches to enable any object to be inserted as a key since almost all objects are immutable in Meson anyway. |
Already fixed by this PR,I think: #6166 |
Fixes PR mesonbuild#6166 and more specifically commit 4e460f0 that tried to make sure the type of a key variable is a string but checked the type of the value instead. Extends test common/228's limited coverage, its only test case had (surprise) a string value. Also avoid reserved python keyword 'dict' and potentially confusing string 'key'. Implements mesonbuild#5231 for real.
Almost, see PR #6279 above (tagging @scivision) In the mean time and for people with meson_version <= 0.52, re-sharing a smart workaround @eli-schwartz shared on IRC: str_keys = [['one', '1'], ['two', '2'], ['three', '3']]
foreach key in str_keys: do_things(key[0], key[1]) This is basically re-implementing a dict manually with a multidimensional list. A bit tedious, but nowhere near as tedious as "unrolling" the |
Oh, cool, I can drop my multidimensional lists soon. \o/ |
Fixes PR #6166 and more specifically commit 4e460f0 that tried to make sure the type of a key variable is a string but checked the type of the value instead. Extends test common/228's limited coverage, its only test case had (surprise) a string value. Also avoid reserved python keyword 'dict' and potentially confusing string 'key'. Implements #5231 for real.
oh wait, actually k = 'somekey'
d = {k:1}
message(d[k]) -> ERROR: Key somekey is not in dict |
Ok, I did a real refactor of dict: #6281 There was too much code duplication for my taste, and I found a few inconsistencies like: # This was not raising error
k = 'a'
d = {k:1, 'a':2}
# This was not allowed, as well as any function call that returns string
d = {'a' / 'b':1} |
I believe #6281 fixed this issue |
I would expect this code to be equivalent to:
Instead, it raises a parsing error:
Seems like an unreasonable limitation?
The text was updated successfully, but these errors were encountered: