Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #1818
This PR adds a specific parse error which detects upfront nonsensical contract annotations. More precisely, when a bare constant (null, boolean, string, number) or a bare array is used as a contract in a type expression or in an annotation. This will hopefully catch common typo like using
:
instead of=
when coming from JSON-like languages.The initial design tried to include a bit of context, to print a special note such as "Did you mean to use
=
instead of:
as in ...." when the error happen in the annotation of a record field definition. However, this wasn't trivial to do, because the error is currently a parsing error which is raised as soon as such an invalid contract appears in a type position. Not doing that and "catching" the error only later for record fields requires to annoyingly change several rule of the grammar (or rather to have specialized ad-hoc version of them just for record fields, which don't raise the error right away but bubble it up).For now this PR is already a good improvement. If we really want to include more context, we can do so at the price of a bit of complexity, or we can also raise the error later in the pipeline, for example during walking/typechecking.