Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASTy reader: add support for Scala 3.0.0-M3 #9394

Merged
merged 1 commit into from Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions project/DottySupport.scala
Expand Up @@ -12,8 +12,8 @@ import sbt.librarymanagement.{
* Settings to support validation of TastyUnpickler against the release of dotty with the matching TASTy version
*/
object TastySupport {
val supportedTASTyRelease = "3.0.0-M2" // TASTy version 25.1
val scala3Compiler = "org.scala-lang" % "scala3-compiler_3.0.0-M2" % supportedTASTyRelease
val supportedTASTyRelease = "3.0.0-M3" // TASTy version 26.1
val scala3Compiler = "org.scala-lang" % "scala3-compiler_3.0.0-M3" % supportedTASTyRelease
}
bishabosha marked this conversation as resolved.
Show resolved Hide resolved

/** Settings needed to compile with Dotty,
Expand Down
4 changes: 3 additions & 1 deletion src/compiler/scala/tools/nsc/tasty/TreeUnpickler.scala
Expand Up @@ -639,7 +639,7 @@ class TreeUnpickler[Tasty <: TastyUniverse](
case tag @ (VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM) =>
symbolAtCurrent()
skipTree()
case IMPORT =>
case IMPORT | EXPORT =>
skipTree()
case PACKAGE =>
processPackage(end => implicit ctx => indexStats(end))
Expand Down Expand Up @@ -886,6 +886,8 @@ class TreeUnpickler[Tasty <: TastyUniverse](
readIndexedMember()
case IMPORT =>
unsupportedTermTreeError("import statement")
case EXPORT =>
unsupportedTermTreeError("export statement")
case PACKAGE =>
unsupportedTermTreeError("package statement")
case _ =>
Expand Down
1 change: 1 addition & 0 deletions src/compiler/scala/tools/nsc/tasty/bridge/NameOps.scala
Expand Up @@ -52,6 +52,7 @@ trait NameOps { self: TastyUniverse =>
final val AnyKind: String = "AnyKind"
final val TupleCons: String = "*:"
final val Tuple: String = "Tuple"
final val Matchable: String = "Matchable"

val ContextFunctionN = raw"ContextFunction(\d+)".r
val FunctionN = raw"Function(\d+)".r
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/scala/tools/nsc/tasty/bridge/TypeOps.scala
Expand Up @@ -346,7 +346,7 @@ trait TypeOps { self: TastyUniverse =>
}

private val SyntheticScala3Type =
raw"^(?:&|\||AnyKind|(?:Context)?Function\d+|\*:|Tuple)$$".r
raw"^(?:&|\||AnyKind|(?:Context)?Function\d+|\*:|Tuple|Matchable)$$".r

def selectType(name: TastyName.TypeName, prefix: Type)(implicit ctx: Context): Type = selectType(name, prefix, prefix)
def selectType(name: TastyName.TypeName, prefix: Type, space: Type)(implicit ctx: Context): Type = {
Expand All @@ -365,6 +365,7 @@ trait TypeOps { self: TastyUniverse =>
case tpnme.TupleCons => genTupleIsUnsupported("scala.*:")
case tpnme.Tuple if !ctx.mode.is(ReadParents) => genTupleIsUnsupported("scala.Tuple")
case tpnme.AnyKind => u.definitions.AnyTpe
case tpnme.Matchable => u.definitions.AnyTpe
case _ => lookupType
}

Expand Down
4 changes: 3 additions & 1 deletion src/compiler/scala/tools/tasty/TastyFormat.scala
Expand Up @@ -15,7 +15,7 @@ package scala.tools.tasty
object TastyFormat {

final val header: Array[Int] = Array(0x5C, 0xA1, 0xAB, 0x1F)
val MajorVersion: Int = 25
val MajorVersion: Int = 26
val MinorVersion: Int = 1

final val ASTsSection = "ASTs"
Expand Down Expand Up @@ -205,6 +205,7 @@ object TastyFormat {
final val TERMREFin = 174
final val TYPEREFin = 175
final val SELECTin = 176
final val EXPORT = 177

final val METHODtype = 180

Expand Down Expand Up @@ -404,6 +405,7 @@ object TastyFormat {
case TERMREFin => "TERMREFin"
case TYPEREFin => "TYPEREFin"
case SELECTin => "SELECTin"
case EXPORT => "EXPORT"

case REFINEDtype => "REFINEDtype"
case REFINEDtpt => "REFINEDtpt"
Expand Down
22 changes: 22 additions & 0 deletions test/tasty/run/src-2/tastytest/TestIOApp.scala
@@ -0,0 +1,22 @@
package tastytest

/** test calling $init$ on IOApp parent */
object TestIOApp extends Suite("TestIOApp") {

def randOver5 = scala.util.Random.nextInt(5) + 5

object Static extends IOApp.Simple {
def run = assert(randOver5 >= 5)
}

test("static IOApp")(Static.run)

test("local IOApp") {
val Local = new IOApp.Simple {
def run = assert(randOver5 >= 5)
}
Local.run
}


}
10 changes: 10 additions & 0 deletions test/tasty/run/src-2/tastytest/TestMatchables.scala
@@ -0,0 +1,10 @@
package tastytest

object TestMatchables extends Suite("TestMatchables") {

test(assert(Matchables.foo == true))
test(assert(Matchables.bar("hello") === "hello"))
test(assert(new Matchables.baz(23).a === 23))
test(assert(new Matchables.qux(5.0).a === 5.0))

}
15 changes: 15 additions & 0 deletions test/tasty/run/src-2/tastytest/TestTraitInitsBase.scala
@@ -0,0 +1,15 @@
package tastytest

/** test calling $init$ on TraitInitsBase.SubTrait parent */
object TestTraitInitsBase extends Suite("TestTraitInitsBase") {

object Static extends TraitInitsBase.SubTrait {}

test("static SubTrait")(assert(Static.foo === 23))

test("local SubTrait") {
val Local = new TraitInitsBase.SubTrait {}
assert(Local.foo === 23)
}

}
7 changes: 7 additions & 0 deletions test/tasty/run/src-2/tastytest/TestValueOfErasure.scala
@@ -0,0 +1,7 @@
package tastytest

object TestValueOfErasure extends Suite("TestValueOfErasure") {

test(assert(ValueOfErasure.reify[23] === 23))

}
23 changes: 23 additions & 0 deletions test/tasty/run/src-3/tastytest/IOApp.scala
@@ -0,0 +1,23 @@
package tastytest

trait IOApp {
protected val foo = 23

def run(args: List[String]): Int

final def main(args: Array[String]): Unit = {
sys.exit(run(args.toList))
}

}

object IOApp {
trait Simple extends IOApp {
def run: Unit

final def run(args: List[String]): Int = {
run
0
}
}
}
15 changes: 15 additions & 0 deletions test/tasty/run/src-3/tastytest/Matchables.scala
@@ -0,0 +1,15 @@
package tastytest

object Matchables {

def foo: Matchable = true

def bar[A <: Matchable](a: A) = a match {
case a: A => a
}

class baz[A](val a: A) extends Matchable

class qux[A <: Matchable](val a: A)

}
8 changes: 8 additions & 0 deletions test/tasty/run/src-3/tastytest/TraitInitsBase.scala
@@ -0,0 +1,8 @@
package tastytest

trait TraitInitsBase {
val foo = 23
}
object TraitInitsBase {
trait SubTrait extends TraitInitsBase
}
5 changes: 5 additions & 0 deletions test/tasty/run/src-3/tastytest/ValueOfErasure.scala
@@ -0,0 +1,5 @@
package tastytest

object ValueOfErasure {
def reify[I <: Int](implicit I: ValueOf[I]): I = valueOf[I]
}