Skip to content

Commit e51ec21

Browse files
committed
add failing test: demo transparent inline can not see forwarders at typer
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.
1 parent 57b6a8c commit e51ec21

File tree

6 files changed

+82
-0
lines changed

6 files changed

+82
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package a
2+
3+
import scala.annotation.unroll
4+
5+
// new project with a single file, first compile via Zinc
6+
object A {
7+
8+
def foo(s: String, x: Int): String = s + x
9+
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package b
2+
3+
import a.*
4+
5+
// Add a separate file in the same project as A, second compile via Zinc
6+
object B {
7+
transparent inline def caller = A.foo("abc", 2)
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package a
2+
import b.*
3+
4+
import scala.annotation.unroll
5+
6+
// modify A.scala and add a parameter to foo, and add C, third compile via Zinc
7+
object A {
8+
9+
def foo(s: String, x: Int, @unroll b: Boolean = true): String = s + x + b
10+
11+
}
12+
13+
// C is the same compilation unit as A, and inlines B.caller, so its TASTy will see the forwarder
14+
// where the associated file came from source
15+
object C {
16+
val res = B.caller
17+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
lazy val commonSettings = Seq(
2+
scalacOptions += "-experimental",
3+
)
4+
5+
lazy val printSettings = Seq(
6+
scalacOptions += "-Yprint-tasty",
7+
)
8+
9+
lazy val a_v1 = project.in(file("a_v1"))
10+
.settings(commonSettings)
11+
.settings(
12+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "v2-input"
13+
)
14+
15+
lazy val a_v2 = project.in(file("a_v2"))
16+
.settings(commonSettings)
17+
.settings(printSettings)
18+
.settings(
19+
Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "v2-input",
20+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "v3-input"
21+
)
22+
23+
lazy val a_v3 = project.in(file("a_v3"))
24+
.settings(commonSettings)
25+
.settings(
26+
Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "v3-input",
27+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "v3-output"
28+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sbt._
2+
import Keys._
3+
4+
object DottyInjectedPlugin extends AutoPlugin {
5+
override def requires = plugins.JvmPlugin
6+
override def trigger = allRequirements
7+
8+
override val projectSettings = Seq(
9+
scalaVersion := sys.props("plugin.scalaVersion")
10+
)
11+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# compile library A via Zinc, with an initial file A defining method foo
2+
> a_v1/compile
3+
# compile library A via Zinc, for the second time, adding a new file that defines an inline
4+
# method B.caller, calling A.foo
5+
> a_v2/compile
6+
# compile library A via Zinc, for the third time, add a new parameter to A.foo, using @unroll to generate a forwarder
7+
# in the same file A.scala, define object C that inlines B.caller, it should succeed and resolve the new invisible forwarder
8+
> a_v3/compile

0 commit comments

Comments
 (0)