Skip to content

Conversation

@illusionalsagacity
Copy link
Contributor

I managed to find the source of this with Claude's help, though I don't have enough experience with ocaml to know for sure if this is an idiomatic fix.

resolves #8086

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 12, 2025

Open in StackBlitz

rescript

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

@rescript/darwin-arm64

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

@rescript/darwin-x64

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

@rescript/linux-arm64

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

@rescript/linux-x64

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

@rescript/runtime

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

@rescript/win32-x64

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

commit: 8586107

@cknitt cknitt requested a review from cristianoc December 12, 2025 09:30
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.

Is it possible to avoid quoting in the first place instead of un-quoting later?

@cknitt
Copy link
Member

cknitt commented Dec 25, 2025

@cristianoc Codex says:

Avoiding the un-quoting here would mean normalizing escaped identifiers earlier (likely when the parser/typedtree builds Ident.t for escaped names). That’s a broader change and could affect other compiler stages that might be relying on the escaped form. The current fix is a localized workaround in genType that keeps the normalization close to the emission logic.

@cristianoc
Copy link
Collaborator

@cristianoc Codex says:

Avoiding the un-quoting here would mean normalizing escaped identifiers earlier (likely when the parser/typedtree builds Ident.t for escaped names). That’s a broader change and could affect other compiler stages that might be relying on the escaped form. The current fix is a localized workaround in genType that keeps the normalization close to the emission logic.

That's a generic laziness claim rather then: you need to change X, Y, Z. These are 23 places, not worth it.

@cristianoc
Copy link
Collaborator

that said, fighting laziness requires resources: such as knowing when to shrink the context, make more things available, know when to push back etc

So feel free to use your judgment on whether it's worth the effort and dig deeper. Or just merge as is.

@illusionalsagacity illusionalsagacity marked this pull request as draft December 25, 2025 15:01
@illusionalsagacity
Copy link
Contributor Author

illusionalsagacity commented Dec 25, 2025

After cutting Opus loose on attempting to unquote, it reverted the unquoting change in

let name = Ext_ident.unwrap_uppercase_exotic ident in
if name = String.empty then (
let end_pos = position scanner in
scanner.err ~start_pos ~end_pos
(Diagnostics.message "A quoted identifier can't be empty string.");
Token.Lident ident)
else if Ext_ident.is_uident name then Token.Lident ident
(* Exotic ident with uppercase letter should be encoded to avoid confusing in OCaml parsetree *)
else Token.Lident name

There's a test failure in exotic_labels_test.cmj with an assertion failure in compiler/ml/env.ml. This is the key issue - the parsetree is getting confused. Let me look at this test file and the env.ml assertion.

The error is:
Fatal error: exception File "compiler/ml/env.ml", line 838, characters 63-69: Assertion failed

This is exactly what the original comment was warning about - "Exotic ident with uppercase letter should be encoded to avoid confusing in OCaml parsetree".Let me look at the exotic_labels_test.res file and the env.ml file to understand what's happening.

Investigating the original pull request reveals critical insights about identifier management. The OCaml type checker fundamentally requires quoted uppercase identifiers for correct internal storage and lookup. Attempting to remove quoting at the scanner level would catastrophically break type checking mechanisms. The localized fix in the genType module represents the most appropriate solution.

it's quoted here with the comment introduced in this pr

@illusionalsagacity illusionalsagacity marked this pull request as ready for review December 25, 2025 16:23

let sanitize_type_name name =
name
name |> Ext_ident.unwrap_uppercase_exotic
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this fixes type \"UppercaseName" being emitted literally, breaking the typescript syntax

I managed to find the source of this with Claude's help, though I don't
have enough experience with ocaml to know for sure if this is an
idiomatic fix.

resolves rescript-lang#8086

Signed-off-by: Rob <[email protected]>
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.

v12 regression; gentype of record with escaped record fields generates invalid Typescript code

3 participants