Skip to content

Commit a0ae794

Browse files
committed
WIP: use classDenot.findMember
1 parent 2991784 commit a0ae794

File tree

28 files changed

+165
-57
lines changed

28 files changed

+165
-57
lines changed

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

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,21 +1184,41 @@ class TreeUnpickler(reader: TastyReader,
11841184
case SELECTin =>
11851185
var sname = readName()
11861186
val qual = readTerm()
1187-
val owner = readType().typeSymbol
1187+
val ownerTpe = readType()
1188+
val owner = ownerTpe.typeSymbol
11881189
val SignedName(name, sig, target) = sname: @unchecked // only methods with params use SELECTin
11891190
val qualType = qual.tpe.widenIfUnstable
11901191
val prefix = ctx.typeAssigner.maybeSkolemizePrefix(qualType, name)
1191-
def matchOverload(denot: SingleDenotation) =
1192-
val sym = denot.symbol
1193-
sym.exists
1194-
&& sym.owner == owner
1195-
&& sym.targetName == target
1196-
&& sym.signature == sig
1197-
val denot = qualType.findMember(name, prefix).filterWithPredicate(matchOverload)
1198-
val select = makeSelect(qual, name, denot)
1199-
if !denot.exists && ctx.settings.YstrictTasty.value then
1192+
def overloadNotFound(select: Tree, symPart: String) =
12001193
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})")
1194+
i"""While unpickling, I was looking in `$qual` (of widened type: ${qual.tpe.widen})
1195+
|but could not find method `$name` (${sname.info}):
1196+
| - $symPart.""".stripMargin)
1197+
// def matchOverload(denot: SingleDenotation) =
1198+
// val sym = denot.symbol
1199+
// sym.exists
1200+
// && sym.owner == owner
1201+
// && sym.targetName == target
1202+
// && sym.signature == sig
1203+
// val denot = qualType.findMember(name, prefix).filterWithPredicate(matchOverload)
1204+
val denot =
1205+
// TODO: handle refinements
1206+
val cls = ownerTpe.classSymbol
1207+
if !cls.exists then NoDenotation
1208+
else
1209+
val clsDenot = cls.asClass.classDenot
1210+
val d0 = clsDenot.findMember(name, cls.thisType, EmptyFlags, EmptyFlags).atSignature(sig, target)
1211+
if !d0.symbol.exists || d0.symbol.isAccessibleFrom(prefix) then d0.asSeenFrom(prefix)
1212+
else
1213+
clsDenot.findMember(name, cls.thisType, EmptyFlags, excluded=Private)
1214+
.atSignature(sig, target)
1215+
.asSeenFrom(prefix)
1216+
val select = makeSelect(qual, name, denot)
1217+
if !(owner.exists && denot.exists) && ctx.settings.YstrictTasty.value then
1218+
val symPart =
1219+
if !owner.exists then i"its defining type ${ownerTpe} could not be found"
1220+
else i"defined in ${owner.showLocated}"
1221+
overloadNotFound(select, symPart)
12021222
else
12031223
select
12041224
case REPEATED =>
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:all"),
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: 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 refinement in library A', it changes the parameter names
6+
> a-changes/compile
7+
# compile B, from tasty, against A', it should continue compile: named arguments still ok.
8+
> c/compile

sbt-dotty/sbt-test/source-dependencies/tasty-add-refinement-incompat/test

Lines changed: 0 additions & 9 deletions
This file was deleted.

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

Lines changed: 0 additions & 12 deletions
This file was deleted.

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

Lines changed: 0 additions & 12 deletions
This file was deleted.

sbt-dotty/sbt-test/source-dependencies/tasty-add-refinement/test

Lines changed: 0 additions & 8 deletions
This file was deleted.
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): Unit = ()
7+
}
8+
9+
trait BoxInt extends Box0[Int]
10+
11+
val box: BoxInt = new BoxInt {}
12+
13+
}
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+
7+
trait BoxInt extends Box0[Int] {
8+
def append(a: Int): Unit = ()
9+
}
10+
11+
val box: BoxInt = new BoxInt {}
12+
13+
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import a.*
22

33
object B extends App {
4-
A.box.append(a = 0)
4+
A.box.append(0)
55
}
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+
# move a method to its super type in library A'
6+
> a-changes/compile
7+
# compile B, from tasty, against A', it should compile: we can find the method in a supertype.
8+
> c/compile
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): Unit = ()
7+
}
8+
9+
trait BoxInt extends Box0[Int]
10+
11+
val box: BoxInt = new BoxInt {}
12+
13+
}
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): Unit = ()
7+
}
8+
9+
trait BoxInt extends Box0[Int] {
10+
override def append(a: Int): Unit = ()
11+
}
12+
13+
val box: BoxInt = new BoxInt {}
14+
15+
}
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: 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+
# remove an override in library A'
6+
> a-changes/compile
7+
# compile B, from tasty, against A', it should compile: we can find the method in a supertype.
8+
> c/compile

tests/pos/i8516.scala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
val x: Function1[Int, Int] { def apply(arg: Int): Int } = x => x
22
val x1 = x
33
val y = x.apply(arg = 1)
4-
5-
val m: [T] => (arg: T) => T = [T] => (arg: T) => arg
6-
val m1 = m
7-
val n = m1(arg = 23)

tests/pos/tasty-named-arguments.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait Fn[-T, R] { def apply(t: T): R }
2+
3+
val f: Fn[Int, Int] { def apply(arg: Int): Int } = x => x
4+
val g = f.apply(arg = 1)
5+
6+
val m: [T] => (arg: T) => T = [T] => (arg: T) => arg
7+
val n = m.apply(arg = 23)
8+
9+
trait KeyValuePair { type Value; def value: Value }
10+
11+
val d: (kvp: KeyValuePair) => kvp.Value = _.value
12+
val e = d.apply(kvp = new { type Value = Int; val value = 23 } )
13+
14+
val c: (i: Int) ?=> i.type = x ?=> x
15+
val i = c.apply(using 0)

0 commit comments

Comments
 (0)