qsharp-compiler
qsharp-compiler copied to clipboard
Improve error message for how to give type annotations
For an operation
operation Foo<'T> () : 'T {
return (new 'T[0])[0];
}
calling it in another operation
operation Bar() : Unit {
let _ = Foo();
}
results in an error "The type annotation 'a is ambiguous. More type annotations or usage context may be needed."
This error message is only actionable if it is clear to people where to put the type annotation and what the syntax it. I suggest making it more actionable. The error message used to have an example: "Please provide explicit type arguments, e.g. Op<Int, Double>(arg)."
The problem is that different situations need different actions... sometimes adding type arguments to an identifier is the best option, but other times it is not ideal (when simply using a variable in context could cause the type to be inferred), or not possible. For example, when []
is ambiguous it needs to be replaced with EmptyArray
before a type can be annotated. Having the error message tell you to write F<T>
when you have []
would be confusing, I think.
I see your point. I think what would make sense here is to add a page to the Q# language docs and give a link to that in the error message.