Right. But the code with the "error" was still legal in the programming language. The "error" was in the logic of the quick sort algorithm.
So the question asked for a desk check of the quick sort algorithm. So the question tested understanding of the quick sort algorithm and ability to desk check. Considering the content of the course, that seemed like a reasonable question.
I'm fully in agreement that usually humans should not spend their time doing what compilers can do faster and better. Indeed when I was teaching my wife our AI language, I advised her not to try very hard to get all the punctuation, language details, syntax, etc. correct and, instead, just to let our compiler tell her where it wanted to object.
Anybody who thinks an exam is a place to prove their own cleverness relative to their students shouldn’t be teaching. How pointless.