Skip to content

Fix #12729: Don't encode <init> and <clinit> only. #12901

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
Jun 25, 2021

Conversation

mlachkar
Copy link
Contributor

@mlachkar mlachkar commented Jun 22, 2021

In addition, reject <init> and <clinit> in the parser, so that
users don't write them in source code.
fixes #12729

@@ -0,0 +1,3 @@
class Test(i: Int):
val `<init>` = "init" // error: Illegal backquoted identifier: `<init>` and `<clinit>` are forbidden
Copy link
Member

@smarter smarter Jun 22, 2021

Choose a reason for hiding this comment

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

You should also test that class `<init>` and def `<init>` are rejected

@mlachkar mlachkar force-pushed the fix-name-with-smaller-than branch from 1dd1d24 to ef27b1e Compare June 24, 2021 09:11
@mlachkar mlachkar requested a review from smarter June 24, 2021 12:45
Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM, but this PR also adds an empty .scalafmt.conf file, is that intentional?

Comment on lines 345 to 346
length >= 6 &&
head == '<' && (this == StdNames.nme.CONSTRUCTOR || this == StdNames.nme.STATIC_CONSTRUCTOR)
Copy link
Member

Choose a reason for hiding this comment

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

This can be simplified to just checking if this is CONSTRUCTOR or STATIC_CONSTRUCTOR, the checks for length and head aren't needed anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you're right! thanks

@smarter
Copy link
Member

smarter commented Jun 24, 2021

Very minor point but when fixing up a mistake in a previous commit, don't hesitate to squash these commits together and push-force, this makes the git history more readable.

@mlachkar mlachkar force-pushed the fix-name-with-smaller-than branch from 1492159 to 58ff556 Compare June 24, 2021 13:25
In addition, reject `<init>` and `<clinit>` in the parser, so that
users don't write them in source code.
@mlachkar mlachkar force-pushed the fix-name-with-smaller-than branch from 58ff556 to 30191db Compare June 24, 2021 13:27
@bishabosha bishabosha merged commit 8163bff into scala:master Jun 25, 2021
@Kordyjan Kordyjan added this to the 3.0.2 milestone Aug 2, 2023
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.

Scala 2 regression: free-form names in backticks crash at runtime
4 participants