Skip to content

In module declaration treat M = { as if it were M : { #7527

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
merged 1 commit into from
May 28, 2025

Conversation

cristianoc
Copy link
Collaborator

@cristianoc cristianoc commented May 27, 2025

A common mistake is to write this in an interface file:

module M = { let x: int }

where the correct syntax is:

module M : { let x: int }

This PR parses the former as if it were the latter. So it compiles and will reformat to the latter.
An alternative is to give an error message with a suggestion to change the code.

Copy link

pkg-pr-new bot commented May 27, 2025

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7527

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7527

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7527

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7527

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7527

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7527

commit: 7ee821a

@cristianoc
Copy link
Collaborator Author

@mediremi thoughts?

@cknitt
Copy link
Member

cknitt commented May 27, 2025

Ran into this quite a few times myself.

Just a thought, couldn't we do it the other way around?
I.e. use = in both .res and .resi, and reformat : to =?

Or is there any reason to use : here other than that's what OCaml does?

@mediremi
Copy link
Contributor

This is great, thanks @cristianoc!

@cristianoc
Copy link
Collaborator Author

Ran into this quite a few times myself.

Just a thought, couldn't we do it the other way around? I.e. use = in both .res and .resi, and reformat : to =?

Or is there any reason to use : here other than that's what OCaml does?

It's by analogy to let x = 3 vs let x : int in implementation/interface files. The former takes an expression, the latter takes a type. so : ... is the pattern one expects for types.
In the case of modules, = is for module values, and : is for module types.

@cristianoc cristianoc requested review from cknitt and zth May 27, 2025 11:11
Copy link
Member

@cknitt cknitt left a comment

Choose a reason for hiding this comment

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

👍 Could you add a CHANGELOG entry?

@cristianoc cristianoc force-pushed the lenient-module-declaration branch from a417a92 to 7ee821a Compare May 28, 2025 07:41
@cristianoc cristianoc merged commit e63147f into master May 28, 2025
16 checks passed
@cristianoc cristianoc deleted the lenient-module-declaration branch May 28, 2025 08:04
@cristianoc cristianoc restored the lenient-module-declaration branch May 28, 2025 15:07
@cristianoc cristianoc deleted the lenient-module-declaration branch May 28, 2025 15:10
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