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

Fix deriving accessors in uncurried mode #6687

Merged

Conversation

JonoPrest
Copy link
Contributor

@JonoPrest JonoPrest commented Mar 20, 2024

Closes #6492

Uncurried mode breaks deriving(accessors)

This PR converts the derived accessor functions into uncurried functions if Config is "Uncurried".

Previously (example from test added)

@@uncurried
@deriving(accessors)
type variant = | Num(int) 

//Asserts the correct signature for derived accessor
let _numAlias: int => variant = num

//Asserts that inference works when composing
//with derived functions
let compose = (a, accessor) => accessor(a)
let _composedNum = compose(1, num)

would error as below

  4 │
  5 │ //Asserts the correct signature for derived accessor
  6 │ let _numAlias: int => variant = num
  7 │
  8 │ //Asserts that inference works when composing

  This function is a curried function where an uncurried function is expected

@zth
Copy link
Collaborator

zth commented Mar 20, 2024

Impressive! Ping @cristianoc who's best to review this.

@zth zth requested a review from cristianoc March 20, 2024 20:15
@zth
Copy link
Collaborator

zth commented Mar 20, 2024

Should probably ship this in 11.1. Mind changing the base branch to that? 11.0_release

@@ -0,0 +1,15 @@
var p = require("child_process");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think a build test is not required for this, as the issue shows with some simple files that don't compile.
Adding a file to jscomp/test should be enough, as compile errors would be picked up.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Plus the compiled output would be checked in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok great thanks for the feedback. I'll do that 👍🏼

@JonoPrest JonoPrest force-pushed the fix-deriving-accessors-uncurried branch from 7a69b50 to a8edae4 Compare March 21, 2024 08:53
@JonoPrest JonoPrest changed the base branch from master to 11.0_release March 21, 2024 08:53
@JonoPrest
Copy link
Contributor Author

Apologies @cristianoc made a mistake with the rebase if you are mid review, busy fixing now.

@JonoPrest JonoPrest force-pushed the fix-deriving-accessors-uncurried branch from a8edae4 to f22be9c Compare March 21, 2024 09:00
@JonoPrest
Copy link
Contributor Author

Impressive! Ping @cristianoc who's best to review this.

Thanks @zth! Just rebased and I'll implement the changes suggested by Cristiano 👍🏼

@JonoPrest
Copy link
Contributor Author

JonoPrest commented Mar 21, 2024

Hey @cristianoc,

Note I've moved the tests out of the build test folder. I also caught a bug realising I was not checking for Variants without parameters. So I've made a tweak to the derive projector file and added a test case for this.

The reason I initially had it as a build test was because I wanted to show in a commit that it was failing and have a passing test that asserts the failure. Then in the following commit that fixes the behaviour invert the assertion that shows its fixed as I like reading git history that tells a story like that 😄

Out of interest is there a nice simple way to assert there should be some sort of compile failure?

@JonoPrest JonoPrest force-pushed the fix-deriving-accessors-uncurried branch from 67609f4 to 55cf92e Compare March 21, 2024 09:55
@JonoPrest JonoPrest force-pushed the fix-deriving-accessors-uncurried branch from 55cf92e to d8cdb20 Compare March 21, 2024 10:01
Copy link
Collaborator

@cristianoc cristianoc left a comment

Choose a reason for hiding this comment

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

Looks great

@zth zth merged commit 2ad77e5 into rescript-lang:11.0_release Mar 21, 2024
14 checks passed
@zth
Copy link
Collaborator

zth commented Mar 21, 2024

Very well done @JonoPrest!

@JonoPrest
Copy link
Contributor Author

Very well done @JonoPrest!

Thanks @zth and thanks for the review @cristianoc, very grateful for your dedication to rescript and openness to contribution 🙏🏼

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.

@deriving(accessors) generates curried functions in uncurried mode
3 participants