Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add InvalidContractError #1824

Merged
merged 1 commit into from
Feb 21, 2024
Merged

Add InvalidContractError #1824

merged 1 commit into from
Feb 21, 2024

Conversation

yannham
Copy link
Member

@yannham yannham commented Feb 19, 2024

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.

This commit adds a specific parse error which detects upfront
non-sensical 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
@yannham yannham requested review from jneem and vkleen February 19, 2024 16:45
@github-actions github-actions bot temporarily deployed to pull request February 19, 2024 16:49 Inactive
@yannham yannham added this pull request to the merge queue Feb 21, 2024
Merged via the queue into master with commit f8b9fd6 Feb 21, 2024
5 checks passed
@yannham yannham deleted the feat/invalid-contract-error branch February 21, 2024 10:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

{a : "str"} evaluates into a function
2 participants