fix: dicts and list need _holderify for fallback
This commit is contained in:
parent
a73791b529
commit
0358445b6e
|
@ -799,7 +799,7 @@ The result of this is undefined and will become a hard error in a future Meson r
|
|||
index = posargs[0]
|
||||
fallback = None
|
||||
if len(posargs) == 2:
|
||||
fallback = posargs[1]
|
||||
fallback = self._holderify(posargs[1])
|
||||
elif len(posargs) > 2:
|
||||
m = 'Array method \'get()\' only takes two arguments: the ' \
|
||||
'index and an optional fallback value if the index is ' \
|
||||
|
@ -845,7 +845,7 @@ The result of this is undefined and will become a hard error in a future Meson r
|
|||
return obj[key]
|
||||
|
||||
if len(posargs) == 2:
|
||||
fallback = posargs[1]
|
||||
fallback = self._holderify(posargs[1])
|
||||
if isinstance(fallback, mparser.BaseNode):
|
||||
return self.evaluate_statement(fallback)
|
||||
return fallback
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
project('set and get')
|
||||
|
||||
var1 = 'test1.txt'
|
||||
var2 = files('test1.txt')
|
||||
var2 = files('test1.txt')[0]
|
||||
|
||||
# Use is_disabler for accessing variables
|
||||
assert(var1 == 'test1.txt')
|
||||
|
@ -9,7 +9,7 @@ assert(not is_disabler(var2))
|
|||
|
||||
# Ensure that set variables behave correctly
|
||||
set_variable('var3', 'test2.txt')
|
||||
set_variable('var4', files('test2.txt'))
|
||||
set_variable('var4', files('test2.txt')[0])
|
||||
|
||||
assert(var3 == 'test2.txt')
|
||||
assert(not is_disabler(var4))
|
||||
|
@ -35,3 +35,29 @@ assert(var7 == 'test2.txt')
|
|||
assert(not is_disabler(var8))
|
||||
assert(get_variable('var9') == 'test2.txt')
|
||||
assert(not is_disabler(get_variable('var0')))
|
||||
|
||||
# test dict get
|
||||
dict = {'a': var2}
|
||||
|
||||
dict_t1 = dict['a']
|
||||
dict_t2 = dict.get('a')
|
||||
dict_t3 = dict.get('a', var2)
|
||||
dict_t4 = dict.get('b', var2)
|
||||
|
||||
assert(not is_disabler(dict_t1))
|
||||
assert(not is_disabler(dict_t2))
|
||||
assert(not is_disabler(dict_t3))
|
||||
assert(not is_disabler(dict_t4))
|
||||
|
||||
# test lists
|
||||
list = [var2]
|
||||
|
||||
list_t1 = list[0]
|
||||
list_t2 = list.get(0)
|
||||
list_t3 = list.get(0, var2)
|
||||
list_t4 = list.get(1, var2)
|
||||
|
||||
assert(not is_disabler(list_t1))
|
||||
assert(not is_disabler(list_t2))
|
||||
assert(not is_disabler(list_t3))
|
||||
assert(not is_disabler(list_t4))
|
||||
|
|
Loading…
Reference in New Issue