Skip to content

Commit 2991784

Browse files
committed
add more tasty forward compat tests
1 parent 97c6969 commit 2991784

File tree

35 files changed

+310
-20
lines changed

35 files changed

+310
-20
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class ScalaSettings extends Settings.SettingGroup with CommonScalaSettings {
155155
val Yhelp: Setting[Boolean] = BooleanSetting("-Y", "Print a synopsis of private options.")
156156
val Ycheck: Setting[List[String]] = PhasesSetting("-Ycheck", "Check the tree at the end of")
157157
val YcheckMods: Setting[Boolean] = BooleanSetting("-Ycheck-mods", "Check that symbols and their defining trees have modifiers in sync.")
158+
val YstrictTasty: Setting[Boolean] = BooleanSetting("-Ystrict-tasty", "Increase strictness of TASTy unpickler when resolving symbols in other compilation units.")
158159
val Ydebug: Setting[Boolean] = BooleanSetting("-Ydebug", "Increase the quantity of debugging output.")
159160
val YdebugTrace: Setting[Boolean] = BooleanSetting("-Ydebug-trace", "Trace core operations.")
160161
val YdebugFlags: Setting[Boolean] = BooleanSetting("-Ydebug-flags", "Print all flags of definitions.")

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,8 +1195,12 @@ class TreeUnpickler(reader: TastyReader,
11951195
&& sym.targetName == target
11961196
&& sym.signature == sig
11971197
val denot = qualType.findMember(name, prefix).filterWithPredicate(matchOverload)
1198-
// TODO: if denot == NoDenotation then ???
1199-
makeSelect(qual, name, denot)
1198+
val select = makeSelect(qual, name, denot)
1199+
if !denot.exists && ctx.settings.YstrictTasty.value then
1200+
typer.ErrorReporting.errorTree(select,
1201+
i"While unpickling, I was looking in (${qual.denot}: ${qual.tpe}) but could not find method $name (defined in ${owner.showLocated}, ${sname.info})")
1202+
else
1203+
select
12001204
case REPEATED =>
12011205
val elemtpt = readTpt()
12021206
SeqLiteral(until(end)(readTerm()), elemtpt)

sbt-dotty/sbt-test/source-dependencies/tasty-add-overload/a-changes/A.scala

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@ package a
22

33
object A {
44

5-
trait Box0[A] {
5+
class Buf[A] {
66
def append(a: A): this.type = this
7-
def append(a: String): Unit = ()
7+
def append(a: A*): this.type = this
88
}
99

10-
trait BoxInt extends Box0[Int] {
11-
override def append(a: Int): this.type = this
12-
}
13-
14-
val box: BoxInt = new BoxInt {}
15-
1610
}

sbt-dotty/sbt-test/source-dependencies/tasty-add-overload/a/A.scala

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@ package a
22

33
object A {
44

5-
trait Box0[A] {
5+
class Buf[A] {
66
def append(a: A): this.type = this
7-
def append(a: String): Unit = ()
87
}
98

10-
trait BoxInt extends Box0[Int]
11-
12-
val box: BoxInt = new BoxInt {}
13-
149
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import a.*
22

3-
object B extends App {
4-
A.box.append(0)
3+
object B {
4+
val foo = new A.Buf[Seq[Double]]
5+
val bar = Seq.empty[Double]
6+
foo.append(bar)
57
}

sbt-dotty/sbt-test/source-dependencies/tasty-add-overload/build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ lazy val `a-changes` = project.in(file("a-changes"))
1414
Compile / classDirectory := (ThisBuild / baseDirectory).value / "c-input"
1515
)
1616

17-
lazy val c = project.in(file("c"))
17+
lazy val c = project.in(file("."))
1818
.settings(
19-
scalacOptions ++= Seq("-from-tasty"),
19+
scalacOptions ++= Seq("-from-tasty", "-Ystrict-tasty", "-Ycheck:readTasty"),
2020
Compile / sources := Seq(new java.io.File("c-input/B.tasty")),
2121
Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "c-input",
2222
Compile / classDirectory := (ThisBuild / baseDirectory).value / "c-output"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
# compile library A
12
> a/compile
3+
# compile library B, from source, against A
24
> b/compile
5+
# add a new overload to library A'
36
> a-changes/compile
7+
# compile B, from tasty, against A', it should still compile: the overload does not conflict
48
> c/compile
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package a
2+
3+
object A {
4+
5+
trait Box0[A] {
6+
def append(a: A): this.type = this
7+
}
8+
9+
trait BoxInt extends Box0[Int] {
10+
override def append(a: Int): this.type = this
11+
}
12+
13+
val box: BoxInt = new BoxInt {}
14+
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package a
2+
3+
object A {
4+
5+
trait Box0[A] {
6+
def append(a: A): this.type = this
7+
}
8+
9+
trait BoxInt extends Box0[Int]
10+
11+
val box: BoxInt = new BoxInt {}
12+
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import a.*
2+
3+
object B extends App {
4+
A.box.append(0)
5+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
lazy val a = project.in(file("a"))
2+
.settings(
3+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "b-input"
4+
)
5+
6+
lazy val b = project.in(file("b"))
7+
.settings(
8+
Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "b-input",
9+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "c-input"
10+
)
11+
12+
lazy val `a-changes` = project.in(file("a-changes"))
13+
.settings(
14+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "c-input"
15+
)
16+
17+
lazy val c = project.in(file("."))
18+
.settings(
19+
scalacOptions ++= Seq("-from-tasty", "-Ystrict-tasty", "-Ycheck:readTasty"),
20+
Compile / sources := Seq(new java.io.File("c-input/B.tasty")),
21+
Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "c-input",
22+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "c-output"
23+
)
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % sys.props("plugin.version"))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# compile library A
2+
> a/compile
3+
# compile library B, from source, against A
4+
> b/compile
5+
# add a new override to library A'
6+
> a-changes/compile
7+
# compile B, from tasty, against A', it should still compile: the override is forward compatible
8+
> c/compile
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package a
2+
3+
object A {
4+
5+
trait Fn[-T1, +R] { def apply(v1: T1): R }
6+
7+
val fn0: Fn[Int, Int] { def apply(arg: Int): Int } = x => x
8+
9+
val fn = fn0
10+
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package a
2+
3+
object A {
4+
5+
trait Fn[-T1, +R] { def apply(v1: T1): R }
6+
7+
val fn0: Fn[Int, Int] = x => x
8+
9+
val fn = fn0
10+
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import a.*
2+
3+
object B extends App {
4+
A.fn(v1 = 0)
5+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
lazy val a = project.in(file("a"))
2+
.settings(
3+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "b-input"
4+
)
5+
6+
lazy val b = project.in(file("b"))
7+
.settings(
8+
Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "b-input",
9+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "c-input"
10+
)
11+
12+
lazy val `a-changes` = project.in(file("a-changes"))
13+
.settings(
14+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "c-input"
15+
)
16+
17+
lazy val c = project.in(file("."))
18+
.settings(
19+
scalacOptions ++= Seq("-from-tasty", "-Ystrict-tasty", "-Ycheck:readTasty"),
20+
Compile / sources := Seq(new java.io.File("c-input/B.tasty")),
21+
Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "c-input",
22+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "c-output"
23+
)
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % sys.props("plugin.version"))
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# compile library A
2+
> a/compile
3+
# compile library B, from source, against A
4+
> b/compile
5+
# add a refinement in library A'
6+
> a-changes/compile
7+
# compile B, from tasty, against A', it should fail to compile: the refinement of `Fn.apply` has changed its
8+
# named arguments.
9+
-> c/compile
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package a
2+
3+
object A {
4+
5+
trait Box[A] {
6+
def append(a: A): Unit = ()
7+
}
8+
9+
val box: Box[Int] { def append(a: Int): Unit } =
10+
new Box[Int] { override def append(a: Int): Unit = () }
11+
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package a
2+
3+
object A {
4+
5+
trait Box[A] {
6+
def append(a: A): Unit = ()
7+
}
8+
9+
val box: Box[Int] =
10+
new Box[Int] {}
11+
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import a.*
2+
3+
object B extends App {
4+
A.box.append(a = 0)
5+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
lazy val a = project.in(file("a"))
2+
.settings(
3+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "b-input"
4+
)
5+
6+
lazy val b = project.in(file("b"))
7+
.settings(
8+
Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "b-input",
9+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "c-input"
10+
)
11+
12+
lazy val `a-changes` = project.in(file("a-changes"))
13+
.settings(
14+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "c-input"
15+
)
16+
17+
lazy val c = project.in(file("."))
18+
.settings(
19+
scalacOptions ++= Seq("-from-tasty", "-Ystrict-tasty", "-Ycheck:readTasty"),
20+
Compile / sources := Seq(new java.io.File("c-input/B.tasty")),
21+
Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "c-input",
22+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "c-output"
23+
)
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % sys.props("plugin.version"))
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# compile library A
2+
> a/compile
3+
# compile library B, from source, against A
4+
> b/compile
5+
# add a new refinement to library A'
6+
> a-changes/compile
7+
# compile B, from tasty, against A', it should still compile: the refinement is forward compatible
8+
> c/compile
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package a
2+
3+
object A {
4+
5+
trait Fn[-T1, +R] { def apply(v1: T1): R }
6+
7+
val fn0: Fn[Int, Int] { def apply(arg: Int): Int } = x => x
8+
9+
val fn = fn0
10+
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package a
2+
3+
object A {
4+
5+
trait Fn[-T1, +R] { def apply(v1: T1): R }
6+
7+
val fn0: Fn[Int, Int] { def apply(int: Int): Int } = x => x
8+
9+
val fn = fn0
10+
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import a.*
2+
3+
object B extends App {
4+
A.fn(int = 0)
5+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
lazy val a = project.in(file("a"))
2+
.settings(
3+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "b-input"
4+
)
5+
6+
lazy val b = project.in(file("b"))
7+
.settings(
8+
Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "b-input",
9+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "c-input"
10+
)
11+
12+
lazy val `a-changes` = project.in(file("a-changes"))
13+
.settings(
14+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "c-input"
15+
)
16+
17+
lazy val c = project.in(file("."))
18+
.settings(
19+
scalacOptions ++= Seq("-from-tasty", "-Ystrict-tasty", "-Ycheck:readTasty"),
20+
Compile / sources := Seq(new java.io.File("c-input/B.tasty")),
21+
Compile / unmanagedClasspath += (ThisBuild / baseDirectory).value / "c-input",
22+
Compile / classDirectory := (ThisBuild / baseDirectory).value / "c-output"
23+
)
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % sys.props("plugin.version"))

0 commit comments

Comments
 (0)