Skip to content

Accommodate internal initial-digit identifiers#4334

Merged
JordanMartinez merged 1 commit into
purescript:masterfrom
rhendric:rhendric/fix-digit-initial-vars
May 20, 2022
Merged

Accommodate internal initial-digit identifiers#4334
JordanMartinez merged 1 commit into
purescript:masterfrom
rhendric:rhendric/fix-digit-initial-vars

Conversation

@rhendric

Copy link
Copy Markdown
Member

The motivating example is the xyzIsSymbol style of variable name that
can be created by CoreFn.CSE.

Description of the change

Fixes issue reported here. This is a fix for an issue triggered by an unreleased feature, so I didn't create a fix changelog entry for it, just an internal entry (because the fix could potentially have consequences on things other than the new feature).


Checklist:

  • Added a file to CHANGELOG.d for this PR (see CHANGELOG.d/README.md)
  • Added myself to CONTRIBUTORS.md (if this is my first contribution)
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation
  • Added a test for the contribution (if applicable)

@JordanMartinez JordanMartinez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To clarify, what happens if there is a top-level member named _two or _two2? Would there be a naming clash between these?

@rhendric

Copy link
Copy Markdown
Member Author

Oh, underscore was a poor choice, wasn't it? I'll reuse $$ then; that shouldn't be able to collide with anything. (identCharToText never produces consecutive dollar signs, and no reserved word or built-in would start with a digit.)

@rhendric rhendric force-pushed the rhendric/fix-digit-initial-vars branch from 0617143 to 85f30ba Compare May 20, 2022 19:51
@JordanMartinez

Copy link
Copy Markdown
Contributor

Oh, underscore was a poor choice, wasn't it? I'll reuse $$ then; that shouldn't be able to collide with anything. (identCharToText never produces consecutive dollar signs, and no reserved word or built-in would start with a digit.)

Yeah, I think that should work.

The motivating example is the `xyzIsSymbol` style of variable name that
can be created by `CoreFn.CSE`.
@rhendric rhendric force-pushed the rhendric/fix-digit-initial-vars branch from 85f30ba to 6fb439c Compare May 20, 2022 20:10
@JordanMartinez

JordanMartinez commented May 20, 2022

Copy link
Copy Markdown
Contributor

On another note, should there be a golden test for this in the optimize tests? To ensure that the outputted JS doesn't have a name clash with a similarly named _two top-level member?

@rhendric

Copy link
Copy Markdown
Member Author

I think all an optimize test would do is ensure that the generated identifier looks the same, not that it doesn't collide with something else. We could write such a test but it doesn't seem to me like it would be worth it; I have a hard time imagining how the $$ prefix changes unintentionally, and if someone changes it intentionally then all that the failing optimize test will communicate is that they did what they intended to do.

What I'd much rather have would be something like a QuickCheck property that asserts that identToJs is injective (over the domain of inputs for which it doesn't error). We don't seem to have much of that sort of unit testing for simple and small units of code that don't change often, but I'd write it if you also think it'd be a good idea.

@JordanMartinez

Copy link
Copy Markdown
Contributor

I think all an optimize test would do is ensure that the generated identifier looks the same, not that it doesn't collide with something else. We could write such a test but it doesn't seem to me like it would be worth it; I have a hard time imagining how the $$ prefix changes unintentionally, and if someone changes it intentionally then all that the failing optimize test will communicate is that they did what they intended to do.

What I'd much rather have would be something like a QuickCheck property that asserts that identToJs is injective (over the domain of inputs for which it doesn't error). We don't seem to have much of that sort of unit testing for simple and small units of code that don't change often, but I'd write it if you also think it'd be a good idea.

Gotcha. Then, I don't think it's needed for this small fix.

@JordanMartinez JordanMartinez merged commit 8181c4f into purescript:master May 20, 2022
@rhendric rhendric deleted the rhendric/fix-digit-initial-vars branch May 20, 2022 21:35
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