qsharp-compiler icon indicating copy to clipboard operation
qsharp-compiler copied to clipboard

Incorrect error range when calling an operation specialization in a lambda function

Open bettinaheim opened this issue 3 years ago • 1 comments

Describe the bug

The following code produces a cryptic and misplaced error: image

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.

bettinaheim avatar Feb 17 '22 01:02 bettinaheim

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.

bamarsha avatar Apr 14 '22 17:04 bamarsha