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

Add regression test for issue 18726 #20318

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/interactive/Completion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
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(
"""
|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
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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(
"""
|object A {
| "".repea@@
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this actually working? I think I actually had to turn it off and -release options is removed:

private val forbiddenDoubleOptions = Set("-release")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, but I don't understand the question. Are you asking about how the test is implemented or how are we handling the release flag ?

Copy link
Contributor

Choose a reason for hiding this comment

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

How are the tests working? And maybe we need to stop removing the flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I guess it is because I passed it as -release:8 and it is a single argument on the list, thus it is not removed ? We should remove this line tho beacuse -release 8 is a valid scala flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you remember why we added this check in the first place ?

Copy link
Contributor

Choose a reason for hiding this comment

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

It might have been interfering with some other options and it seemed not important for frontend phases scalameta/metals#3812

Copy link
Contributor

Choose a reason for hiding this comment

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

I just tested it and seems to work ok with that removed.

|}""".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
)
13 changes: 13 additions & 0 deletions presentation-compiler/test/dotty/tools/pc/utils/JRE.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dotty.tools.pc.utils

object JRE:

def getJavaMajorVersion: Int =
val javaVersion = sys.env.get("java.specification.version").filter(!_.isEmpty())

javaVersion match
case Some(version) if version.startsWith("1.8") => 8
case Some(version) => version.toInt // it is better to crash during tests than to run incorrect suite
case None => 8


Loading