aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/mparser.py2
-rw-r--r--test cases/common/228 add dict variable key/meson.build19
2 files changed, 15 insertions, 6 deletions
diff --git a/mesonbuild/mparser.py b/mesonbuild/mparser.py
index 1baf051..80ffefd 100644
--- a/mesonbuild/mparser.py
+++ b/mesonbuild/mparser.py
@@ -682,7 +682,7 @@ class Parser:
# + 1 to colno to point to the actual string, not the opening quote
raise ParseException('Duplicate dictionary key: {}'.format(s.value), self.getline(), s.lineno, s.colno + 1)
a.set_kwarg(s.value, key_value)
- elif isinstance(s, IdNode) and isinstance(key_value, StringNode):
+ elif isinstance(s, IdNode) and isinstance(s.value, str):
for key in a.kwargs:
if s.value == key.value:
raise ParseException('Duplicate dictionary variable key: {}'.format(s.value), self.getline(), s.lineno, s.colno)
diff --git a/test cases/common/228 add dict variable key/meson.build b/test cases/common/228 add dict variable key/meson.build
index b39c17e..faa6854 100644
--- a/test cases/common/228 add dict variable key/meson.build
+++ b/test cases/common/228 add dict variable key/meson.build
@@ -1,12 +1,21 @@
project('add dictionary entry using string variable as key', meson_version: '>=0.52')
-dict = {}
+dict1 = {}
# A variable to be used as a key
-key = 'myKey'
+testkey1 = 'myKey1'
+testkey2 = 'myKey2'
# Add new entry using the variable
-dict += {key : 'myValue'}
+dict1 += {testkey1 : 'myValue'}
+dict1 += {testkey2 : 42}
-# Test that the stored value is correct
-assert(dict[key] == 'myValue', 'Incorrect value retrieved from dictionary')
+# Test that the stored values are correct
+assert(dict1[testkey1] == 'myValue',
+ 'Incorrect string value retrieved from dictionary - variable key')
+assert(dict1['myKey1'] == 'myValue',
+ 'Incorrect string value retrieved from dictionary - literal key')
+assert(dict1[testkey2] == 42,
+ 'Incorrect int value retrieved from dictionary - variable key')
+assert(dict1['myKey2'] == 42,
+ 'Incorrect int value retrieved from dictionary - literal key')