Disallow ternary operator with different types on the rhs
I.e. 1 ? 2 : "foo" is no longer allowed
This commit is contained in:
parent
803de56a44
commit
518633d26a
|
@ -817,6 +817,11 @@ static Value doTernary(ParseState state)
|
|||
goto err;
|
||||
state->flags = oldflags;
|
||||
|
||||
if (! valueSameType(v1, v2)) {
|
||||
exprErr(state, _("types must match"), NULL);
|
||||
goto err;
|
||||
}
|
||||
|
||||
valueFree(cond ? v2 : v1);
|
||||
return cond ? v1 : v2;
|
||||
}
|
||||
|
|
|
@ -299,8 +299,10 @@ runroot rpm --eval '%{expr:"a"=!"b"}'
|
|||
runroot rpm --eval '%{expr:4+}'
|
||||
runroot rpm --eval '%{expr:bare}'
|
||||
runroot rpm --eval '%{expr:1/0}'
|
||||
runroot rpm --eval '%{expr:0 < 1 ? "a" : 1*"a"}'
|
||||
runroot rpm --eval '%{expr:0 < 1 ? 1*"a" : "a"}'
|
||||
runroot rpm --eval '%{expr:0 < 1 ? 2 : 1*"a"}'
|
||||
runroot rpm --eval '%{expr:0 < 1 ? 1*"a" : 2}'
|
||||
runroot rpm --eval '%{expr:0 < 1 ? 2 : "a"}'
|
||||
runroot rpm --eval '%{expr:0 < 1 ? "a" : 2}'
|
||||
],
|
||||
[1],
|
||||
[],
|
||||
|
@ -313,8 +315,10 @@ error: unexpected end of expression: 4+
|
|||
error: bare words are no longer supported, please use "...": bare
|
||||
error: ^
|
||||
error: division by zero: 1/0
|
||||
error: types must match: 0 < 1 ? "a" : 1*"a"
|
||||
error: types must match: 0 < 1 ? 1*"a" : "a"
|
||||
error: types must match: 0 < 1 ? 2 : 1*"a"
|
||||
error: types must match: 0 < 1 ? 1*"a" : 2
|
||||
error: types must match: 0 < 1 ? 2 : "a"
|
||||
error: types must match: 0 < 1 ? "a" : 2
|
||||
])
|
||||
AT_CLEANUP
|
||||
|
||||
|
|
Loading…
Reference in New Issue