Skip to content

Commit

Permalink
add failing test: demo transparent inline can not see forwarders at t…
Browse files Browse the repository at this point in the history
…yper

At typer, when transparent inline methods are expanded, unroll forwarders
are not yet generated.

So if we define forwarders for the first time, in the same compilation
unit that inlines a call to the forwarder, then it will fail.

Perhaps we can detect this and suspend the unit, otherwise it would seem
unreasonable complexity to generate forwarders in typer.
  • Loading branch information
bishabosha committed Oct 8, 2024
1 parent 4006af0 commit 8a1887c
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 0 deletions.
10 changes: 10 additions & 0 deletions sbt-test/tasty-compat/add-param-unroll2/a_v1/A.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package a

import scala.annotation.unroll

// new project with a single file, first compile via Zinc
object A {

def foo(s: String, x: Int): String = s + x

}
8 changes: 8 additions & 0 deletions sbt-test/tasty-compat/add-param-unroll2/a_v2/B.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package b

import a.*

// Add a separate file in the same project as A, second compile via Zinc
object B {
transparent inline def caller = A.foo("abc", 2)
}
17 changes: 17 additions & 0 deletions sbt-test/tasty-compat/add-param-unroll2/a_v3/A.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package a
import b.*

import scala.annotation.unroll

// modify A.scala and add a parameter to foo, and add C, third compile via Zinc
object A {

def foo(s: String, x: Int, @unroll b: Boolean = true): String = s + x + b

}

// C is the same compilation unit as A, and inlines B.caller, so its TASTy will see the forwarder
// where the associated file came from source
object C {
val res = B.caller
}
28 changes: 28 additions & 0 deletions sbt-test/tasty-compat/add-param-unroll2/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
lazy val commonSettings = Seq(
scalacOptions += "-experimental",
)

lazy val printSettings = Seq(
scalacOptions += "-Yprint-tasty",
)

lazy val a_v1 = project.in(file("a_v1"))
.settings(commonSettings)
.settings(
Compile / classDirectory := (ThisBuild / baseDirectory).value / "v2-input"
)

lazy val a_v2 = project.in(file("a_v2"))
.settings(commonSettings)
.settings(printSettings)
.settings(
Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "v2-input",
Compile / classDirectory := (ThisBuild / baseDirectory).value / "v3-input"
)

lazy val a_v3 = project.in(file("a_v3"))
.settings(commonSettings)
.settings(
Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "v3-input",
Compile / classDirectory := (ThisBuild / baseDirectory).value / "v3-output"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import sbt._
import Keys._

object DottyInjectedPlugin extends AutoPlugin {
override def requires = plugins.JvmPlugin
override def trigger = allRequirements

override val projectSettings = Seq(
scalaVersion := sys.props("plugin.scalaVersion")
)
}
8 changes: 8 additions & 0 deletions sbt-test/tasty-compat/add-param-unroll2/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# compile library A via Zinc, with an initial file A defining method foo
> a_v1/compile
# compile library A via Zinc, for the second time, adding a new file that defines an inline
# method B.caller, calling A.foo
> a_v2/compile
# compile library A via Zinc, for the third time, add a new parameter to A.foo, using @unroll to generate a forwarder
# in the same file A.scala, define object C that inlines B.caller, it should succeed and resolve the new invisible forwarder
> a_v3/compile

0 comments on commit 8a1887c

Please sign in to comment.