qsharp-compiler
qsharp-compiler copied to clipboard
Incorrect error range when calling an operation specialization in a lambda function
Describe the bug
The following code produces a cryptic and misplaced error:

Expected behavior
The compiler should produce a more descriptive error message with a range that is either the whole lambda expression, the lambda body, or just the functor application in the lambda body.
The range is misplaced, but to clarify, I think the error message is correct. #1410 fixes the range to refer to the use of op:
op -> Adjoint op();
~~
^ QS5017: No suitable adjoint specialization exists.
Given that op is called in a function lambda, the compiler infers that op must be a function. But functions cannot have adjoint specializations. Hence op is not a valid operand for Adjoint.
Maybe it's confusing that the information from the call expression (Adjoint op)() propagates backwards to generate an error for Adjoint op. That's caused by the difference between relational and class constraints - the knowledge of op being a function is a relational constraint, which is applied first, before the class constraint of adjointability is checked.