aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbuild2/variable.cxx11
-rw-r--r--libbuild2/variable.txx4
-rw-r--r--tests/type/json/testscript10
3 files changed, 20 insertions, 5 deletions
diff --git a/libbuild2/variable.cxx b/libbuild2/variable.cxx
index ab65237..078c13a 100644
--- a/libbuild2/variable.cxx
+++ b/libbuild2/variable.cxx
@@ -1799,9 +1799,16 @@ namespace build2
{
case json_type::null:
{
- // Return empty to be consistent with other places.
+ // Note that here we cannot return empty (e.g., to be consistent with
+ // other places) because we treat empty name (as opposed to empty
+ // names) as string, not null (see to_json_value() above).
//
-#if 0
+ // Thankfully this version of reverse() is only used when json_value
+ // representation is needed as part of a container. Which means in
+ // "consumption" contexts (e.g., result of subscript) null will still
+ // decay to empty.
+ //
+#if 1
return name ("null");
#else
return name ();
diff --git a/libbuild2/variable.txx b/libbuild2/variable.txx
index 12a2667..0b831e9 100644
--- a/libbuild2/variable.txx
+++ b/libbuild2/variable.txx
@@ -1347,6 +1347,10 @@ namespace build2
// value), but we don't yet have pair<> as value type so we let the generic
// implementation return an untyped pair.
//
+ // BTW, one negative consequence of returning untyped pair is that
+ // $first()/$second() don't return types values either, which is quite
+ // unfortunate for something like json_map.
+ //
template <typename K, typename V>
const map_value_type<K, V>
value_traits<map<K, V>>::value_type = build2::value_type // VC14 wants =
diff --git a/tests/type/json/testscript b/tests/type/json/testscript
index 6beaf5d..36287b7 100644
--- a/tests/type/json/testscript
+++ b/tests/type/json/testscript
@@ -468,15 +468,19 @@
print ($m[1])
print $type($m[1])
print ($m[2][b])
+ print ($m[0])
+ print ($m[-1])
EOI
- -1@"" 0@"" 1@[1,2] 2@{"a":1,"b":2}
- -1 ""
- 0 ""
+ -1@null 0@null 1@[1,2] 2@{"a":1,"b":2}
+ -1 null
+ 0 null
1 [1,2]
2 {"a":1,"b":2}
[1,2]
json
2
+
+
EOO
}