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 removing function argument when argument is unit #4042

Conversation

klofberg
Copy link

This PR fixes the issue: #4041

@alfonsogarciacaro
Copy link
Member

This is tricky, if we do this we generate code that doesn't feel as native because all functions accepting unit will have a useless argument.

I think we were replacing all identifiers with unit value to avoid this situation, not sure why it didn't work in this case

@klofberg
Copy link
Author

Do you think it would be possible to remove the argument from the body instead?

@alfonsogarciacaro
Copy link
Member

Interesting, I thought we were doing this already but apparently not 😅
I've sent a naive implementation #4044 but it seems to work

@klofberg
Copy link
Author

Great :-) I'm new to developing the fable compiler but I would be happy to help. Should I try to add tests? Maybe I can investigate how it affects Rust and Python?

@MangelMaxime
Copy link
Member

Should I try to add tests?

Adding tests is a good idea indeed, but it will need to be done @alfonsogarciacaro PR.

We have 2 types of tests:

  • "Standard" tests which are located under the tests/JavaScript, tests/Python, etc. folders
  • Integration tests which check compiler errors and code generation too under the tests/Integration

If you want to contribute to Fable feel free to ask questions and we will try to help you.

@klofberg
Copy link
Author

I'm uncertain how to run the tests? If i run them with dotnet test all tests passes but I assume that they aren't checked with fable? When I try ./src/Fable.Cli/bin/Debug/net8.0/fable tests/Js/Main --exclude Fable.Core --noCache I get a lot of errors.

Is this the best place for me to ask questions or should I use Discord or something else?

@MangelMaxime
Copy link
Member

@klofberg When working with Fable you should use the build.sh and build.bat script (run build.sh --help to learn more)

They will give you all the commands that you can use to work with Fable.

In this case, it would be something like build.sh test javascript

I made Amplifying F# session showing how Fable works: https://amplifyingfsharp.io/sessions/2023-12-15/

@klofberg
Copy link
Author

klofberg commented Feb 11, 2025 via email

@alfonsogarciacaro
Copy link
Member

alfonsogarciacaro commented Feb 14, 2025

@klofberg I'd be more than happy if you cherry-pick the commit (or just copy the code) and continue the PR. An integration test could be a good idea, so we also check that functions with () as argument become argument-less in JS.

To add an integration test you just need to add/edit at project in the tests/Integration/Integration/data directory with the .js.expected files (you can run the tests once first and change the .actual extension). See another project in the same folder as an example.

About Python, it should have the same behavior more or less. The only thing that surprised me is when I checked In Fable repl, Python had unit arguments even if they're supposed to be removed, so I need to investigate this:

let args = FSharp2Fable.Util.discardUnitArg args

@klofberg
Copy link
Author

Sounds good. Thanks for the input and help! I will look at what I can do.

@klofberg
Copy link
Author

@alfonsogarciacaro I've created a new PR #4050 with your code and added a integration test for javascript. I will try to have a look at the Python issue you mention also.

@klofberg klofberg closed this Feb 17, 2025
@klofberg klofberg deleted the fixRemovinFunctionArgWhenArgIsUnit branch February 17, 2025 22:59
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.

3 participants