Skip to content

Backport "Add test cases project for presentation compiler" to 3.3 LTS #131

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

Closed
wants to merge 5 commits into from
Closed
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ on:
- cron: '0 3 * * *' # Every day at 3 AM
workflow_dispatch:

# Cancels any in-progress runs within the same group identified by workflow name and GH reference (branch or tag)
# Cancels any in-progress runs within the same group identified by workflow name and GH reference (branch or tag)
# For example it would:
# - terminate previous PR CI execution after pushing more changes to the same PR branch
# - terminate previous on-push CI run after merging new PR to main
# - terminate previous on-push CI run after merging new PR to main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
Expand Down Expand Up @@ -183,7 +183,7 @@ jobs:
uses: actions/checkout@v4

- name: Test
run: sbt ";scala3-bootstrapped/compile; scala3-bootstrapped/testCompilation; scala3-presentation-compiler-bootstrapped/test; scala3-language-server/test"
run: sbt ";scala3-bootstrapped/compile; scala3-bootstrapped/testCompilation; scala3-presentation-compiler/test; scala3-language-server/test"
shell: cmd

- name: build binary
Expand Down
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ val dist = Build.dist
val `community-build` = Build.`community-build`
val `sbt-community-build` = Build.`sbt-community-build`
val `scala3-presentation-compiler` = Build.`scala3-presentation-compiler`
val `scala3-presentation-compiler-bootstrapped` = Build.`scala3-presentation-compiler-bootstrapped`
val `scala3-presentation-compiler-testcases` = Build.`scala3-presentation-compiler-testcases`

val sjsSandbox = Build.sjsSandbox
val sjsJUnitTests = Build.sjsJUnitTests
Expand Down
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>
case _ =>
tree

def stripNamedArg(tree: Tree) = tree match
case NamedArg(_, arg) => arg
case _ => tree

/** The number of arguments in an application */
def numArgs(tree: Tree): Int = unsplice(tree) match {
case Apply(fn, args) => numArgs(fn) + args.length
Expand Down Expand Up @@ -138,15 +142,15 @@ trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>
def allTermArguments(tree: Tree): List[Tree] = unsplice(tree) match {
case Apply(fn, args) => allTermArguments(fn) ::: args
case TypeApply(fn, args) => allTermArguments(fn)
case Block(_, expr) => allTermArguments(expr)
case Block(Nil, expr) => allTermArguments(expr)
case _ => Nil
}

/** All type and term arguments of an application in a single flattened list */
def allArguments(tree: Tree): List[Tree] = unsplice(tree) match {
case Apply(fn, args) => allArguments(fn) ::: args
case TypeApply(fn, args) => allArguments(fn) ::: args
case Block(_, expr) => allArguments(expr)
case Block(Nil, expr) => allArguments(expr)
case _ => Nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
def recur(t: untpd.Tree): Text = t match
case Apply(fn, Nil) => recur(fn)
case Apply(fn, args) =>
val explicitArgs = args.filterNot(_.symbol.name.is(DefaultGetterName))
val explicitArgs = args.filterNot(untpd.stripNamedArg(_).symbol.name.is(DefaultGetterName))
recur(fn) ~ "(" ~ toTextGlobal(explicitArgs, ", ") ~ ")"
case TypeApply(fn, args) => recur(fn) ~ "[" ~ toTextGlobal(args, ", ") ~ "]"
case Select(qual, nme.CONSTRUCTOR) => recur(qual)
Expand Down
7 changes: 6 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ trait Applications extends Compatibility {
case tp => args.size
}

!isJavaAnnotConstr(methRef.symbol) &&
!isAnnotConstr(methRef.symbol) &&
args.size < requiredArgNum(funType)
}

Expand Down Expand Up @@ -591,6 +591,11 @@ trait Applications extends Compatibility {
def isJavaAnnotConstr(sym: Symbol): Boolean =
sym.is(JavaDefined) && sym.isConstructor && sym.owner.is(JavaAnnotation)


/** Is `sym` a constructor of an annotation? */
def isAnnotConstr(sym: Symbol): Boolean =
sym.isConstructor && sym.owner.isAnnotation

/** Match re-ordered arguments against formal parameters
* @param n The position of the first parameter in formals in `methType`.
*/
Expand Down
2 changes: 1 addition & 1 deletion docs/_spec/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ GEM
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
webrick (1.8.2)
webrick (1.9.1)

PLATFORMS
ruby
Expand Down
16 changes: 16 additions & 0 deletions presentation-compiler-testcases/src/tests/macros/20560.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package tests.macros

import scala.quoted.{Expr, Quotes}

object Macro20560:
transparent inline def loadJavaSqlDriver: Int = ${ loadJavaSqlDriverImpl }

private def loadJavaSqlDriverImpl(using Quotes): Expr[42] =
Class.forName("java.sql.Driver")
'{42}

transparent inline def loadJavaSqlInexisting: Int = ${ loadJavaSqlInexistingImpl }

private def loadJavaSqlInexistingImpl(using Quotes): Expr[42] =
Class.forName("java.sql.Inexisting")
'{42}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import org.junit.runner.RunWith
import scala.meta.pc.CompletionItemPriority

object TestResources:
val scalaLibrary = BuildInfo.ideTestsDependencyClasspath.map(_.toPath).toSeq
val classpath = BuildInfo.ideTestsDependencyClasspath.map(_.toPath).toSeq
val classpathSearch =
ClasspathSearch.fromClasspath(scalaLibrary, ExcludedPackagesHandler.default)
ClasspathSearch.fromClasspath(classpath, ExcludedPackagesHandler.default)

@RunWith(classOf[ReusableClassRunner])
abstract class BasePCSuite extends PcAssertions:
Expand All @@ -38,11 +38,11 @@ abstract class BasePCSuite extends PcAssertions:
val executorService: ScheduledExecutorService =
Executors.newSingleThreadScheduledExecutor()
val testingWorkspaceSearch = TestingWorkspaceSearch(
TestResources.scalaLibrary.map(_.toString)
TestResources.classpath.map(_.toString)
)

lazy val presentationCompiler: PresentationCompiler =
val myclasspath: Seq[Path] = TestResources.scalaLibrary
val myclasspath: Seq[Path] = TestResources.classpath
val scalacOpts = scalacOptions(myclasspath)
val search = new MockSymbolSearch(
testingWorkspaceSearch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,21 @@ class HoverTermSuite extends BaseHoverSuite:
|""".stripMargin
)

@Test def `i20560`=
check(
"val re@@s = tests.macros.Macro20560.loadJavaSqlDriver",
"""```scala
|val res: Int
|```
|""".stripMargin
)

@Test def `i20560-2`=
check(
"val re@@s = tests.macros.Macro20560.loadJavaSqlInexisting",
"", // crashes in the Macro; no type info
)

@Test def `import-rename` =
check(
"""
Expand Down
33 changes: 15 additions & 18 deletions project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1152,27 +1152,25 @@ object Build {
libraryDependencies += ("org.scala-sbt" %% "zinc-apiinfo" % "1.8.0" % Test).cross(CrossVersion.for3Use2_13)
)

lazy val `scala3-presentation-compiler` = project.in(file("presentation-compiler"))
.asScala3PresentationCompiler(NonBootstrapped)
lazy val `scala3-presentation-compiler-bootstrapped` = project.in(file("presentation-compiler"))
.asScala3PresentationCompiler(Bootstrapped)

def scala3PresentationCompiler(implicit mode: Mode): Project = mode match {
case NonBootstrapped => `scala3-presentation-compiler`
case Bootstrapped => `scala3-presentation-compiler-bootstrapped`
}
lazy val `scala3-presentation-compiler` = project.in(file("presentation-compiler"))
.withCommonSettings(Bootstrapped)
.dependsOn(`scala3-compiler-bootstrapped`, `scala3-library-bootstrapped`, `scala3-presentation-compiler-testcases` % "test->test")
.settings(presentationCompilerSettings)
.settings(scala3PresentationCompilerBuildInfo)

def scala3PresentationCompilerBuildInfo(implicit mode: Mode) =
def scala3PresentationCompilerBuildInfo =
Seq(
ideTestsDependencyClasspath := {
val dottyLib = (dottyLibrary / Compile / classDirectory).value
val testCasesLib = (`scala3-presentation-compiler-testcases` / Compile / classDirectory).value
val dottyLib = (`scala3-library-bootstrapped` / Compile / classDirectory).value
val scalaLib =
(dottyLibrary / Compile / dependencyClasspath)
(`scala3-library-bootstrapped` / Compile / dependencyClasspath)
.value
.map(_.data)
.filter(_.getName.matches("scala-library.*\\.jar"))
.toList
dottyLib :: scalaLib
testCasesLib :: dottyLib :: scalaLib
// Nil
},
Compile / buildInfoPackage := "dotty.tools.pc.buildinfo",
Expand Down Expand Up @@ -1231,6 +1229,10 @@ object Build {
)
}

lazy val `scala3-presentation-compiler-testcases` = project.in(file("presentation-compiler-testcases"))
.dependsOn(`scala3-compiler-bootstrapped`)
.settings(commonBootstrappedSettings)

lazy val `scala3-language-server` = project.in(file("language-server")).
dependsOn(dottyCompiler(Bootstrapped)).
settings(commonBootstrappedSettings).
Expand Down Expand Up @@ -1959,7 +1961,7 @@ object Build {

// FIXME: we do not aggregate `bin` because its tests delete jars, thus breaking other tests
def asDottyRoot(implicit mode: Mode): Project = project.withCommonSettings.
aggregate(`scala3-interfaces`, dottyLibrary, dottyCompiler, tastyCore, `scala3-sbt-bridge`, scala3PresentationCompiler).
aggregate(`scala3-interfaces`, dottyLibrary, dottyCompiler, tastyCore, `scala3-sbt-bridge`, `scala3-presentation-compiler`).
bootstrappedAggregate(`scala3-language-server`, `scala3-staging`,
`scala3-tasty-inspector`, `scala3-library-bootstrappedJS`, scaladoc).
dependsOn(tastyCore).
Expand Down Expand Up @@ -2038,11 +2040,6 @@ object Build {
settings(commonBenchmarkSettings).
enablePlugins(JmhPlugin)

def asScala3PresentationCompiler(implicit mode: Mode): Project = project.withCommonSettings.
dependsOn(dottyCompiler, dottyLibrary).
settings(presentationCompilerSettings).
settings(scala3PresentationCompilerBuildInfo)

def asDist(implicit mode: Mode): Project = project.
enablePlugins(PackPlugin).
withCommonSettings.
Expand Down
25 changes: 25 additions & 0 deletions tests/printing/dependent-annot-default-args.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[[syntax trees at end of typer]] // tests/printing/dependent-annot-default-args.scala
package <empty> {
class annot(x: Any, y: Any) extends annotation.Annotation() {
private[this] val x: Any
private[this] val y: Any
}
final lazy module val annot: annot = new annot()
final module class annot() extends AnyRef() { this: annot.type =>
def $lessinit$greater$default$2: Any @uncheckedVariance = 42
}
final lazy module val dependent-annot-default-args$package:
dependent-annot-default-args$package =
new dependent-annot-default-args$package()
final module class dependent-annot-default-args$package() extends Object() {
this: dependent-annot-default-args$package.type =>
def f(x: Int): Int @annot(x) = x
def test: Unit =
{
val y: Int = ???
val z: Int @annot(y) = f(y)
()
}
}
}

5 changes: 5 additions & 0 deletions tests/printing/dependent-annot-default-args.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class annot(x: Any, y: Any = 42) extends annotation.Annotation
def f(x: Int): Int @annot(x) = x
def test =
val y: Int = ???
val z = f(y)