Skip to content

Commit 7325a37

Browse files
committed
Avoid too precise type for TYPEREFsymbol; restore TestMonad
1 parent cc7fec3 commit 7325a37

File tree

8 files changed

+15
-18
lines changed

8 files changed

+15
-18
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ There is a small set of test files in `/test/tasty/`, here is the procedure (to
1313
- Files matching `/test/tasty/src-2/Test*.scala` are designed to test that symbols from TASTy files are unpickled correctly, so depend on symbols that are defined in `/test/tasty/src-3/*`.
1414
- These are required to pass before they can be committed. (i.e. print "_Suite passed!_" when their main function is run.)
1515
- `/test/tasty/suspended/` are for dotty sources that have not yet been feature implemented.
16+
- Some tests require the Dotty class library on the classpath, to obtain this, just use [coursier](https://get-coursier.io), for example like `scala -classpath out:$(coursier fetch -p ch.epfl.lamp:dotty-library_<VERSION>:<RELEASE>) tastytest.TestHello` to run the `TestHello` suite.
1617

1718
# Welcome!
1819

src/compiler/scala/tools/nsc/tasty/TreeUnpickler.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,12 @@ abstract class TreeUnpickler(reader: TastyReader,
428428
private def readSymNameRef()(implicit ctx: Context): Type = {
429429
val sym = readSymRef()
430430
val prefix = readType()
431-
val res = typeRef(prefix, sym, Nil)
432431
prefix match {
433432
case prefix: ThisType if prefix.sym eq sym.owner /*&& !sym.is(Opaque)*/ =>
434-
res //res.withDenot(sym.denot)
433+
typeRef(NoPrefix, sym, Nil) //res.withDenot(sym.denot)
435434
// without this precaution we get an infinite cycle when unpickling pos/extmethods.scala
436435
// the problem arises when a self type of a trait is a type parameter of the same trait.
437-
case _ => res
436+
case _ => typeRef(prefix, sym, Nil)
438437
}
439438
}
440439

@@ -796,7 +795,9 @@ abstract class TreeUnpickler(reader: TastyReader,
796795
val localCtx = localContext(sym)
797796
val noCycle = tag match {
798797
case DEFDEF =>
799-
assertTasty(!(completer.tastyFlagSet &~ Extension), s"unsupported flags on def: ${completer.tastyFlagSet.show}")
798+
val (isExtension, exceptExtension) = completer.tastyFlagSet.except(Extension)
799+
assertTasty(!exceptExtension, s"unsupported Scala 3 flags on def: ${exceptExtension.show}")
800+
if (isExtension) ctx.log(s"$name is a Scala 3 extension method.")
800801
val tparams = readParams[NoCycle](TYPEPARAM)(localCtx)
801802
val vparamss = readParamss(localCtx)
802803
val tpt = readTpt()(localCtx)
@@ -814,7 +815,7 @@ abstract class TreeUnpickler(reader: TastyReader,
814815
sym.info = if (sym.flags.not(Module)) internal.nullaryMethodType(tpe) else tpe // TODO: really?
815816
NoCycle(at = symAddr)
816817
case TYPEDEF | TYPEPARAM =>
817-
assertTasty(!completer.tastyFlagSet, s"unsupported flags on type: ${completer.tastyFlagSet.show}")
818+
assertTasty(!completer.tastyFlagSet, s"unsupported Scala 3 flags on type: ${completer.tastyFlagSet.show}")
818819
if (sym.isClass) {
819820
sym.owner.ensureCompleted()
820821
readTemplate(symAddr)(localCtx)

test/tasty/src-2/tastytest/ConcreteError.scala

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

test/tasty/src-2/tastytest/TestEmpty.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package tastytest
22

3+
import scala.runtime.ScalaRunTime
4+
35
object TestEmpty {
46

57
def test1 = assert(productString(new EmptyProduct) === "EmptyProduct()")

test/tasty/src-2/tastytest/TestError.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package tastytest
22

33
object TestError {
4-
def test1 = assert((try throw new ConcreteError catch handler) === "ConcreteError")
4+
5+
final class ConcreteError extends AbsError("ConcreteError")
56

67
val handler: PartialFunction[Throwable, String] = {
78
case e: ConcreteError => e.getMessage()
89
}
910

11+
def test1 = assert((try throw new ConcreteError catch handler) === "ConcreteError")
12+
1013
def main(args: Array[String]): Unit = {
1114
test1
1215
println("Suite passed!")

test/tasty/suspended/tastytest/TestMonad.scala renamed to test/tasty/src-2/tastytest/TestMonad.scala

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
package tastytest
22

3-
object TestFunctor {
3+
object TestMonad {
44

55
implicit object ListMonad extends Monad[List] {
6-
7-
def flatMap[A, B](fa: List[A])(f: A => List[B]): List[B] = fa.flatMap(f)
86
def pure[A](x: A): List[A] = x :: Nil
9-
10-
// error: Missing implementation for:
11-
// def map[A, B](fa: Monad.this.F[A])(f: A => B): Monad.this.F[B] // inherited from trait Functor
7+
def flatMap[A, B](fa: List[A])(f: A => List[B]): List[B] = fa.flatMap(f)
128
override def map[A, B](fa: List[A])(f: A => B): List[B] = fa.map(f)
13-
149
}
1510

1611
def pureToString[F[_], A](fa: F[A])(implicit F: Monad[F]): F[String] = F.flatMap(fa)(a => F.pure(a.toString))

test/tasty/src-2/tastytest/package.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
package object tastytest {
2-
import scala.runtime.ScalaRunTime
3-
42
implicit final class SafeEq[T](private val t: T) extends AnyVal {
53
final def ===[U](u: U)(implicit ev: T =:= U): Boolean = t == u
64
}

0 commit comments

Comments
 (0)