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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedundantSyntax: distinguish single and triple quotes #1851

Merged
merged 1 commit into from Sep 10, 2023

Conversation

bjaglin
Copy link
Collaborator

@bjaglin bjaglin commented Aug 27, 2023

馃く

Welcome to Scala 2.13.11 (OpenJDK 64-Bit Server VM, Java 17.0.7).
Type in expressions for evaluation. Or try :help.

scala> s""" \n """ == """ \n """ 
val res0: Boolean = false

scala> s" \n " == " \n "
val res1: Boolean = true

scala> f""" \n """ == """ \n """
val res2: Boolean = false

scala> f" \n " == " \n "
val res3: Boolean = true

scala> raw""" \n """ == """ \n """
val res4: Boolean = true

scala> raw" \n " == " \n "
val res5: Boolean = false

Test input/output had to be duplicated because 2.12 does not support s"my \"quoted\" string"

@bjaglin bjaglin linked an issue Aug 27, 2023 that may be closed by this pull request
@bjaglin
Copy link
Collaborator Author

bjaglin commented Aug 27, 2023

Thanks for the report @bmarker, this was a "fun" fix to make!

@bjaglin
Copy link
Collaborator Author

bjaglin commented Aug 27, 2023

Oh, it's even "funnier" than I thought, it works in 2.13, but the compiler (or scalameta?) has a different output of string interpolation in 2.12 & 3 so we need a better heuristic than syntax.contains("\"\"\"") to capture usage of """ with scalameta...

Also, it seems that scala/scala#8830 was not backported to 2.12, so we can't use the same test input across versions.


b = raw"foo $a \nbar"
b = """foo\nbar\\"""
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this makes sure we still remove the interpolator when we can

b = s"""foo $a bar"""
b = s"""$a"""

b = "foo"
b = f"foo $a%2.2f"
b = "foo \n bar"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this makes sure we still remove the interpolator when we can

@@ -8,18 +8,22 @@ class StringInterpolator {
b = "foo"
b = "foo"
b = s"foo $a bar"
b = "my \"quoted\" string"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this makes sure we still remove the interpolator when we can


b = """foo"""
b =
"""foo
|bar"""
b = s"""my \"quoted\" string"""
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this tests the actual fix for the reported problem

@bjaglin bjaglin marked this pull request as ready for review September 10, 2023 20:43
@bjaglin
Copy link
Collaborator Author

bjaglin commented Sep 10, 2023

cc @gontard as the original rule author for visibility

@bjaglin bjaglin merged commit f4dcc6f into scalacenter:main Sep 10, 2023
8 checks passed
@gontard
Copy link
Contributor

gontard commented Sep 11, 2023

馃憢 Thanks for the fix!

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.

RedundantSyntax changed the resulting string value
2 participants