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

Improve support for Unicode supplementary characters in identifiers and string interpolation (as in Scala 2) #16278

Merged
merged 3 commits into from
Dec 29, 2022

Conversation

som-snytt
Copy link
Contributor

Forward port scala/scala#9805

Fixes #16271

@som-snytt
Copy link
Contributor Author

image

@som-snytt som-snytt marked this pull request as ready for review November 3, 2022 15:15
@SethTisue SethTisue changed the title More unicode support Improve support for Unicode supplementary characters in identifiers and string interpolation (as in Scala 2) Nov 3, 2022
Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

LGTM

@SethTisue
Copy link
Member

SethTisue commented Nov 22, 2022

@som-snytt merge conflict needs resolving

My only other concern before hitting "merge" is to ask whether you looked at whether docs/_docs/internals/syntax.md and/or docs/_docs/reference/syntax.md need to be updated? If you either update those or assure us they don't need updating, then we'll be good to go, here.

@som-snytt
Copy link
Contributor Author

It looks like the fix on Scala 2 had no impact on the spec because it's "Unicode."

@TheElectronWill
Copy link
Contributor

TheElectronWill commented Nov 28, 2022

Could § be allowed too? It seems nonsensical to allow emojis but not the paragraph character, which is on our (ok, on some keyboards).
edit: Ideally, could §someVar be allowed please? 👀 It would make a nice replacement for $ in frontend cases like Laminar.

@som-snytt
Copy link
Contributor Author

Could § be allowed too? It seems nonsensical to allow emojis but not the paragraph character, which is on our keyboards.

In what context? is it punctuation? Not every character is accepted everywhere.

Arbitrary identifiers:

scala> def `§` = 42
def $u00A7: Int

Also, not on my keyboard.

@som-snytt
Copy link
Contributor Author

I guess every five days there is a conflicting push to Scanners.

@som-snytt som-snytt requested review from dwijnand and removed request for SethTisue November 28, 2022 10:26
@TheElectronWill
Copy link
Contributor

TheElectronWill commented Nov 28, 2022

In what context? is it punctuation? Not every character is accepted everywhere.

Yes, the the section sign is in the "punctuation" category. So are !, ? and /, which are all allowed without backticks :)
For coherence, it could be allowed in (at least) the same places as them.

@raquo
Copy link
Contributor

raquo commented Nov 28, 2022

It would make a nice replacement for $ in frontend cases like Laminar.

To clarify Laminar's use case – we tend to prefix variable and method names with $ as a shorthand for "stream of / signal of". It's an easy way to distinguish between similar but different types at a glance, by name alone, e.g.:

val item: Item = ???
val items: List[Item] = ???
val $item: EventStream[Item] = ???
val $items: EventStream[List[Item]] = ???
val $$items: EventStream[EventStream[List[Item]]] = ???
// etc.

This convention arose because $ is the only symbolic character that alphanumeric identifiers can be prefixed with. It's been very useful that way, until we learned that $ is reserved for compiler internals.

I suggest that it would be useful to allow some "keyboard-typeable" special character to be used as a prefix (or alternatively, as a suffix) to identifiers like variable and method names, and if that's not feasible, to perhaps allow characters like §. Emojis are... cool, but they are too visually disruptive to be used for this purpose in my humble opinion.

We only point to § because it's visually similar to $, I don't know enough about the compiler internals to say what is a good idea for the language, just trying to communicate the problem that the lack of $ presents us.

@som-snytt
Copy link
Contributor Author

som-snytt commented Nov 28, 2022

That's an interesting use case. I'd suggest https://github.com/lampepfl/dotty-feature-requests

Alternatively, maybe leading dollar is OK for certain members. A linter could flag violations. That might be an intermediate ground.

@SethTisue SethTisue merged commit 805dda8 into scala:main Dec 29, 2022
@som-snytt som-snytt deleted the issue/16271-supples branch December 29, 2022 15:55
@Kordyjan Kordyjan added this to the 3.3.0 milestone Aug 1, 2023
@TheElectronWill
Copy link
Contributor

TheElectronWill commented Sep 19, 2023

I was thinking about the Laminar case lately, and IMO a good solution would be to use the IDE's capabilities instead of a prefix.
An IDE extension could communicate with the language server to find all the variables of type Stream, Signal, and more, and highlight/underline/whatever-you-want them. It could even display the § prefix, without writing it to the source file 😄

This would eliminate the need for a specific naming convention, and would be customizable to better suit the users' needs.

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.

Improve support for Unicode supplementary characters in identifiers and string interpolation (as in Scala 2)
6 participants