diff options
-rw-r--r-- | build2/parser.cxx | 42 | ||||
-rw-r--r-- | tests/variable/type/buildfile | 4 | ||||
-rw-r--r-- | tests/variable/type/test.out | 1 |
3 files changed, 27 insertions, 20 deletions
diff --git a/build2/parser.cxx b/build2/parser.cxx index 1ecf808..dfe85be 100644 --- a/build2/parser.cxx +++ b/build2/parser.cxx @@ -1594,31 +1594,33 @@ namespace build2 // be the same. Also check that the requested value type doesn't conflict // with the variable type. // - if (type != nullptr) + if (type != nullptr && + var != nullptr && + var->type != nullptr && + var->type != type) { - if (var != nullptr && var->type != nullptr && var->type != type) - fail (l) << "conflicting variable " << var->name << " type " - << var->type->name << " and value type " << type->name; + fail (l) << "conflicting variable " << var->name << " type " + << var->type->name << " and value type " << type->name; + } - if (kind == type::assign) - { - if (type != v.type) - { - v = nullptr; // Clear old value. - v.type = type; - } - } - else + if (kind == type::assign) + { + if (type != v.type) { - if (!v) - v.type = type; - else if (v.type == nullptr) - typify (v, *type, var); - else if (v.type != type) - fail (l) << "conflicting original value type " << v.type->name - << " and append/prepend value type " << type->name; + v = nullptr; // Clear old value. + v.type = type; } } + else if (type != nullptr) + { + if (!v) + v.type = type; + else if (v.type == nullptr) + typify (v, *type, var); + else if (v.type != type) + fail (l) << "conflicting original value type " << v.type->name + << " and append/prepend value type " << type->name; + } if (null) { diff --git a/tests/variable/type/buildfile b/tests/variable/type/buildfile index 85c18e1..a22cddd 100644 --- a/tests/variable/type/buildfile +++ b/tests/variable/type/buildfile @@ -77,4 +77,8 @@ print $v7 # 0 print [uint64] 00 # 0 +v8 = [uint64] 01 +v8 = abc +print $v8 # abc + ./: diff --git a/tests/variable/type/test.out b/tests/variable/type/test.out index 4aea91f..5218221 100644 --- a/tests/variable/type/test.out +++ b/tests/variable/type/test.out @@ -9,3 +9,4 @@ foobarbaz 0 0 0 +abc |