From a2ba08f22cc8423e816875716b85fdb0eee57f42 Mon Sep 17 00:00:00 2001 From: rochala Date: Thu, 2 May 2024 10:53:34 +0200 Subject: [PATCH 1/5] Add regression test for issue 18726 [Cherry-picked cfe13a4cc894753951ad4b2c268b1ea84880a2ac] --- .../completion/CompletionRelease11Suite.scala | 26 +++++++++++++++++++ .../completion/CompletionRelease8Suite.scala | 25 ++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionRelease11Suite.scala create mode 100644 presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionRelease8Suite.scala diff --git a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionRelease11Suite.scala b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionRelease11Suite.scala new file mode 100644 index 000000000000..72192bfb5a00 --- /dev/null +++ b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionRelease11Suite.scala @@ -0,0 +1,26 @@ +package dotty.tools.pc.tests.completion + +import dotty.tools.pc.base.BaseCompletionSuite + +import org.junit.Test +import java.nio.file.Path + +class CompletionRelease11Suite extends BaseCompletionSuite: + + override protected def scalacOptions(classpath: Seq[Path]): Seq[String] = + "-release:11" +: super.scalacOptions(classpath) + + @Test def java11Symbols = + check( + """ + |object A { + | "".repea@@ + |}""".stripMargin, + """repeat(x$0: Int): String + |replaceAll(x$0: String, x$1: String): String + |prependedAll[B >: A](prefix: IterableOnce[B]): IndexedSeq[B] + |prependedAll(prefix: String): String + |prependedAll[B >: Char](prefix: IterableOnce[B]): IndexedSeq[B] + |replaceAllLiterally(literal: String, replacement: String): String + |""".stripMargin + ) diff --git a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionRelease8Suite.scala b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionRelease8Suite.scala new file mode 100644 index 000000000000..ff10a28e1265 --- /dev/null +++ b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionRelease8Suite.scala @@ -0,0 +1,25 @@ +package dotty.tools.pc.tests.completion + +import dotty.tools.pc.base.BaseCompletionSuite + +import org.junit.Test +import java.nio.file.Path + +class CompletionRelease8Suite extends BaseCompletionSuite: + + override protected def scalacOptions(classpath: Seq[Path]): Seq[String] = + "-release:8" +: super.scalacOptions(classpath) + + @Test def noJvm11Symbols = + check( + """ + |object A { + | "".repea@@ + |}""".stripMargin, + """replaceAll(x$0: String, x$1: String): String + |prependedAll[B >: A](prefix: IterableOnce[B]): IndexedSeq[B] + |prependedAll(prefix: String): String + |prependedAll[B >: Char](prefix: IterableOnce[B]): IndexedSeq[B] + |replaceAllLiterally(literal: String, replacement: String): String + |""".stripMargin + ) From 4aed7f599fe68839418e85e0de0725247a2d0477 Mon Sep 17 00:00:00 2001 From: rochala Date: Wed, 28 Aug 2024 18:55:29 +0200 Subject: [PATCH 2/5] Make 11 test start only on jvm 11+ [Cherry-picked f5dc97f99d0e1de92a4b1a31f4a4e44be3133ed4] --- .../completion/CompletionRelease11Suite.scala | 6 +++++ .../completion/CompletionRelease8Suite.scala | 6 +++++ .../test/dotty/tools/pc/utils/JRE.scala | 22 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 presentation-compiler/test/dotty/tools/pc/utils/JRE.scala diff --git a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionRelease11Suite.scala b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionRelease11Suite.scala index 72192bfb5a00..76015a588387 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionRelease11Suite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionRelease11Suite.scala @@ -3,13 +3,19 @@ package dotty.tools.pc.tests.completion import dotty.tools.pc.base.BaseCompletionSuite import org.junit.Test +import org.junit.Before import java.nio.file.Path +import dotty.tools.pc.utils.JRE class CompletionRelease11Suite extends BaseCompletionSuite: override protected def scalacOptions(classpath: Seq[Path]): Seq[String] = "-release:11" +: super.scalacOptions(classpath) + @Before + def beforeMethod(): Unit = + org.junit.Assume.assumeTrue(JRE.getJavaMajorVersion >= 11) + @Test def java11Symbols = check( """ diff --git a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionRelease8Suite.scala b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionRelease8Suite.scala index ff10a28e1265..587cd5a53073 100644 --- a/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionRelease8Suite.scala +++ b/presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionRelease8Suite.scala @@ -3,13 +3,19 @@ package dotty.tools.pc.tests.completion import dotty.tools.pc.base.BaseCompletionSuite import org.junit.Test +import org.junit.Before import java.nio.file.Path +import dotty.tools.pc.utils.JRE class CompletionRelease8Suite extends BaseCompletionSuite: override protected def scalacOptions(classpath: Seq[Path]): Seq[String] = "-release:8" +: super.scalacOptions(classpath) + @Before + def beforeMethod(): Unit = + org.junit.Assume.assumeTrue(JRE.getJavaMajorVersion >= 8) + @Test def noJvm11Symbols = check( """ diff --git a/presentation-compiler/test/dotty/tools/pc/utils/JRE.scala b/presentation-compiler/test/dotty/tools/pc/utils/JRE.scala new file mode 100644 index 000000000000..aefa1633e142 --- /dev/null +++ b/presentation-compiler/test/dotty/tools/pc/utils/JRE.scala @@ -0,0 +1,22 @@ +package dotty.tools.pc.utils + +object JRE: + + def getJavaMajorVersion: Int = + val javaVersion = sys.env.get("java.version").filter(!_.isEmpty()) + + javaVersion match + case Some(version) if version.startsWith("1.8") => 8 + case _ => + scala.util.Try: + val versionMethod = classOf[Runtime].getMethod("version") + versionMethod.nn.setAccessible(true) + val version = versionMethod.nn.invoke(null) + + val majorMethod = version.getClass().getMethod("feature") + majorMethod.nn.setAccessible(true) + val major = majorMethod.nn.invoke(version).asInstanceOf[Int] + major + .getOrElse(8) // Minimal version supported by Scala + + From a355c7731b10dcf9ea4901e6e5c0d848f7d9e1ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Rochala?= <48657087+rochala@users.noreply.github.com> Date: Thu, 29 Aug 2024 10:47:48 +0200 Subject: [PATCH 3/5] Update presentation-compiler/test/dotty/tools/pc/utils/JRE.scala Co-authored-by: Tomasz Godzik [Cherry-picked 07deb553a4f3bd2c72fc746579dc0880c45ccc22] --- .../test/dotty/tools/pc/utils/JRE.scala | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/presentation-compiler/test/dotty/tools/pc/utils/JRE.scala b/presentation-compiler/test/dotty/tools/pc/utils/JRE.scala index aefa1633e142..2f812e1bbf80 100644 --- a/presentation-compiler/test/dotty/tools/pc/utils/JRE.scala +++ b/presentation-compiler/test/dotty/tools/pc/utils/JRE.scala @@ -3,20 +3,11 @@ package dotty.tools.pc.utils object JRE: def getJavaMajorVersion: Int = - val javaVersion = sys.env.get("java.version").filter(!_.isEmpty()) + val javaVersion = sys.env.get("java.specification.version").filter(!_.isEmpty()) javaVersion match case Some(version) if version.startsWith("1.8") => 8 - case _ => - scala.util.Try: - val versionMethod = classOf[Runtime].getMethod("version") - versionMethod.nn.setAccessible(true) - val version = versionMethod.nn.invoke(null) - - val majorMethod = version.getClass().getMethod("feature") - majorMethod.nn.setAccessible(true) - val major = majorMethod.nn.invoke(version).asInstanceOf[Int] - major - .getOrElse(8) // Minimal version supported by Scala + case Some(version) => version + case None => 8 From be07596f7596568c6b3430ae90c7eeecbcc32667 Mon Sep 17 00:00:00 2001 From: rochala Date: Mon, 2 Sep 2024 18:37:34 +0200 Subject: [PATCH 4/5] Fix types [Cherry-picked 0b45f44092d9c00f2e3f89d08eabccb42d78ad67] --- compiler/src/dotty/tools/dotc/interactive/Completion.scala | 3 +-- presentation-compiler/test/dotty/tools/pc/utils/JRE.scala | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/interactive/Completion.scala b/compiler/src/dotty/tools/dotc/interactive/Completion.scala index c1449c7236d9..9a9f7aa78d49 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Completion.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Completion.scala @@ -250,7 +250,7 @@ object Completion: // https://github.com/scalameta/metals/blob/main/mtags/src/main/scala/scala/meta/internal/mtags/KeywordWrapper.scala // https://github.com/com-lihaoyi/Ammonite/blob/73a874173cd337f953a3edc9fb8cb96556638fdd/amm/util/src/main/scala/ammonite/util/Model.scala private def needsBacktick(s: String) = - val chunks = s.split("_", -1).nn + val chunks = s.split("_", -1) val validChunks = chunks.zipWithIndex.forall { case (chunk, index) => chunk.nn.forall(Chars.isIdentifierPart) || @@ -284,7 +284,6 @@ object Completion: if denot.isType then denot.symbol.showFullName else denot.info.widenTermRefExpr.show - def isInNewContext(untpdPath: List[untpd.Tree]): Boolean = untpdPath match case _ :: untpd.New(selectOrIdent: (untpd.Select | untpd.Ident)) :: _ => true diff --git a/presentation-compiler/test/dotty/tools/pc/utils/JRE.scala b/presentation-compiler/test/dotty/tools/pc/utils/JRE.scala index 2f812e1bbf80..d082258c255b 100644 --- a/presentation-compiler/test/dotty/tools/pc/utils/JRE.scala +++ b/presentation-compiler/test/dotty/tools/pc/utils/JRE.scala @@ -7,7 +7,7 @@ object JRE: javaVersion match case Some(version) if version.startsWith("1.8") => 8 - case Some(version) => version + case Some(version) => version.toInt // it is better to crash during tests than to run incorrect suite case None => 8 From b33eb4f01beae34f14d83ec53625efc56fb8d376 Mon Sep 17 00:00:00 2001 From: rochala Date: Thu, 12 Sep 2024 20:24:38 +0200 Subject: [PATCH 5/5] Fix accidentaly removed .nn call and remove -release from forbidden options [Cherry-picked 3078860c15ef937d1f846a5318aeaccae9904f32] --- compiler/src/dotty/tools/dotc/interactive/Completion.scala | 2 +- .../src/main/dotty/tools/pc/ScalaPresentationCompiler.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/interactive/Completion.scala b/compiler/src/dotty/tools/dotc/interactive/Completion.scala index 9a9f7aa78d49..af27a4006140 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Completion.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Completion.scala @@ -250,7 +250,7 @@ object Completion: // https://github.com/scalameta/metals/blob/main/mtags/src/main/scala/scala/meta/internal/mtags/KeywordWrapper.scala // https://github.com/com-lihaoyi/Ammonite/blob/73a874173cd337f953a3edc9fb8cb96556638fdd/amm/util/src/main/scala/ammonite/util/Model.scala private def needsBacktick(s: String) = - val chunks = s.split("_", -1) + val chunks = s.split("_", -1).nn val validChunks = chunks.zipWithIndex.forall { case (chunk, index) => chunk.nn.forall(Chars.isIdentifierPart) || diff --git a/presentation-compiler/src/main/dotty/tools/pc/ScalaPresentationCompiler.scala b/presentation-compiler/src/main/dotty/tools/pc/ScalaPresentationCompiler.scala index e6da8b79164f..218d92c38ffa 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/ScalaPresentationCompiler.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/ScalaPresentationCompiler.scala @@ -60,7 +60,7 @@ case class ScalaPresentationCompiler( val scalaVersion = BuildInfo.scalaVersion private val forbiddenOptions = Set("-print-lines", "-print-tasty") - private val forbiddenDoubleOptions = Set("-release") + private val forbiddenDoubleOptions = Set.empty[String] given ReportContext = folderPath