Fix operator precedence bug in Rust parser

PR rust/29859 points out an operator precedence bug in the Rust
parser.  This patch fixes it and adds a regression test.
This commit is contained in:
Tom Tromey
2022-12-06 07:41:52 -07:00
parent 83f18e5ebe
commit e03698c122
2 changed files with 5 additions and 1 deletions

View File

@ -1398,7 +1398,7 @@ rust_parser::parse_binop (bool required)
break;
}
while (precedence < operator_stack.back ().precedence
while (precedence <= operator_stack.back ().precedence
&& operator_stack.size () > 1)
{
rustop_item rhs = std::move (operator_stack.back ());

View File

@ -412,3 +412,7 @@ if {[lindex $v 0] >= 8} {
gdb_test "python print(gdb.lookup_type('simple::MoreComplicated').dynamic)" \
"True"
}
# The new parser introduced an operator precedence bug.
gdb_test "print 5 * 7 / 5" " = 7"
gdb_test "print 4 - 3 - 1" " = 0"