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

use in top-level expression results in invalid Python syntax #3912

Open
joprice opened this issue Sep 30, 2024 · 2 comments
Open

use in top-level expression results in invalid Python syntax #3912

joprice opened this issue Sep 30, 2024 · 2 comments
Labels

Comments

@joprice
Copy link
Contributor

joprice commented Sep 30, 2024

Description

When useing an IDisposable at the top-level, the generated code contains a return statement, which is not valid outside of the context of a function definition.

Repro code

https://fable.io/repl/#?code=PYBwpgdgBAYghgIwDZgHQGFgCcwChcAuAnuFABpQC8UAlhABZhY0FQDKRAzgWALaoBJACI1OIYJ0Qp8AbQA8AcSTAEcJAD4AurhSsAHgC5yVKBDgEaANzAB5CEiL5dUABQBKE7ihQArpzBQeiZ6Xq5uQA&html=Q&css=Q

Expected and actual results

The expression should be wrapped in something like an IIFE, as is the case for the js backend.

Related information

  • Fable version: 4.19.3
  • Operating system: OSX
@MangelMaxime
Copy link
Member

I didn't even know it was a valid F# syntax to have a function without a name 😅

@joprice
Copy link
Contributor Author

joprice commented Sep 30, 2024

It's not actually a function, but an assignment of a top-level expression to unit, a habit I picked up from ocaml that is similar to x |> ignore<unit>, where if the result type changes, the unused value will be detected. You can reproduce it like this as well:

(
  use x = x
  ()
)

Or

let _ =
  use x = x
  ()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants