Skip to content

Improve error when using '@deriving(accessors)` on a variant with a record arg #6712

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

Merged

Conversation

JonoPrest
Copy link
Contributor

@JonoPrest JonoPrest commented Apr 3, 2024

Closes #6704

Previously

@deriving(accessors)
type t = Struct({a: int})

would error with:

Fatal error: exception File "jscomp/frontend/ast_derive_projector.ml", line 57, characters 42-48: Assertion failed

now we get:

  We've found a bug for you!
  /.../fixtures/DerivingAccessorsRecordParam.res:2:10-25
                                                                                                               
  1 │ @deriving(accessors)
  2 │ type t = Struct({a: int})
  3 │
                                                                                                               
  @deriving(accessors) from a variant record argument is unsupported. Either define the record type separatelyfrom the variant type or use a positional argument.

@JonoPrest JonoPrest force-pushed the improve-derived-from-error branch 2 times, most recently from 139324f to 251420e Compare April 3, 2024 16:24
@fhammerschmidt
Copy link
Member

it actually closes #6704 ;-)
very nice work!

@JonoPrest
Copy link
Contributor Author

it actually closes #6704 ;-) very nice work!

Thanks! Sorry I mis-typed that!

@JonoPrest JonoPrest force-pushed the improve-derived-from-error branch from 251420e to 87b38a6 Compare April 3, 2024 16:41
Copy link
Collaborator

@zth zth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! 🎉

pcd_res;
}
->
let pcd_args =
match pcd_args with
| Pcstr_tuple pcd_args -> pcd_args
| Pcstr_record _ -> assert false
| Pcstr_record _ ->
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this appear twice?
Are there 2 different ways to trigger the error?
In any case better refactor the error message printing and avoid duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, sorry I just copy pasted 👍🏼, the one is for structure gen the other is for signature gen. If it hits the case in one it will also in the other so you will only see one message.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cristianoc I've refactored it. See the following commit. Thanks!

@zth zth merged commit 4a38f30 into rescript-lang:11.0_release Apr 3, 2024
14 checks passed
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.

4 participants