From cfe13a4cc894753951ad4b2c268b1ea84880a2ac 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 --- .../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 f5dc97f99d0e1de92a4b1a31f4a4e44be3133ed4 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+ --- .../tools/pc/base/ReusableClassRunner.scala | 9 ++------ .../completion/CompletionRelease11Suite.scala | 6 +++++ .../completion/CompletionRelease8Suite.scala | 6 +++++ .../test/dotty/tools/pc/utils/JRE.scala | 22 +++++++++++++++++++ 4 files changed, 36 insertions(+), 7 deletions(-) create mode 100644 presentation-compiler/test/dotty/tools/pc/utils/JRE.scala diff --git a/presentation-compiler/test/dotty/tools/pc/base/ReusableClassRunner.scala b/presentation-compiler/test/dotty/tools/pc/base/ReusableClassRunner.scala index 82e697e6e9a1..4999e0ddbc69 100644 --- a/presentation-compiler/test/dotty/tools/pc/base/ReusableClassRunner.scala +++ b/presentation-compiler/test/dotty/tools/pc/base/ReusableClassRunner.scala @@ -13,22 +13,17 @@ class ReusableClassRunner(testClass: Class[BasePCSuite]) testClass.getDeclaredConstructor().newInstance() override def createTest(): AnyRef = instance - override def withBefores( - method: FrameworkMethod, - target: Object, - statement: Statement - ): Statement = - statement override def withAfters( method: FrameworkMethod, target: Object, statement: Statement ): Statement = + val newStatement = super.withAfters(method, target, statement) new Statement(): override def evaluate(): Unit = try - statement.evaluate() + newStatement.evaluate() finally if (isLastTestCase(method)) then instance.clean() 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 07deb553a4f3bd2c72fc746579dc0880c45ccc22 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 --- .../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 0b45f44092d9c00f2e3f89d08eabccb42d78ad67 Mon Sep 17 00:00:00 2001 From: rochala Date: Mon, 2 Sep 2024 18:37:34 +0200 Subject: [PATCH 4/5] Fix types --- 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 1395d9b80b53..4b3c6100d71c 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Completion.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Completion.scala @@ -252,7 +252,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) || @@ -286,7 +286,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 3078860c15ef937d1f846a5318aeaccae9904f32 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 --- 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 4b3c6100d71c..6e86f45237cf 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Completion.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Completion.scala @@ -252,7 +252,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 85de8e7d8439..679fbf000f75 100644 --- a/presentation-compiler/src/main/dotty/tools/pc/ScalaPresentationCompiler.scala +++ b/presentation-compiler/src/main/dotty/tools/pc/ScalaPresentationCompiler.scala @@ -58,7 +58,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