Skip to content

Commit

Permalink
Merge pull request #101 from scalacenter/tasty/support-anykind
Browse files Browse the repository at this point in the history
erase scala.AnyKind to scala.Any
  • Loading branch information
bishabosha authored Jun 15, 2020
2 parents d89de20 + 74b4ebb commit 1e5143e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/compiler/scala/tools/nsc/tasty/bridge/NameOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ trait NameOps { self: TastyUniverse =>
object tpnme {
final val Or: TypeName = TastyName.SimpleName("|").toTypeName
final val And: TypeName = TastyName.SimpleName("&").toTypeName
final val AnyKind: TypeName = TastyName.SimpleName("AnyKind").toTypeName

final val ScalaAnnotationInternal_Repeated: TypeName =
TastyName.qualifiedClass("scala", "annotation", "internal", "Repeated")
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/tasty/bridge/TreeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ trait TreeOps { self: TastyUniverse =>
def SeqLiteral(trees: List[Tree], tpt: Tree): Tree = u.ArrayValue(tpt, trees).setType(tpt.tpe)

def AppliedTypeTree(tpt: Tree, args: List[Tree])(implicit ctx: Context): Tree = {
if (tpt.tpe === AndType) {
if (tpt.tpe === AndTpe) {
u.CompoundTypeTree(u.Template(args, u.noSelfType, Nil)).setType(ui.intersectionType(args.map(_.tpe)))
} else {
u.AppliedTypeTree(tpt, args).setType(defn.AppliedType(tpt.tpe, args.map(_.tpe)))
Expand Down
12 changes: 8 additions & 4 deletions src/compiler/scala/tools/nsc/tasty/bridge/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,19 @@ trait TypeOps { self: TastyUniverse =>

}

/** A type which accepts two type arguments, representing an intersection type
/** A synthetic type `scala.&` which accepts two type arguments, representing an intersection type
* @see https://github.com/lampepfl/dotty/issues/7688
*/
case object AndType extends Type
case object AndTpe extends Type

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 = {
if (prefix.typeSymbol === u.definitions.ScalaPackage && ( name === tpnme.And || name === tpnme.Or ) ) {
if (name === tpnme.And) AndType
if (prefix.typeSymbol === u.definitions.ScalaPackage && (
name === tpnme.And
|| name === tpnme.Or
|| name === tpnme.AnyKind) ) {
if (name === tpnme.And) AndTpe
else if (name === tpnme.AnyKind) u.definitions.AnyTpe // TODO [tasty]: scala.AnyKind can appear in upper bounds of raw type wildcards, but elsewhere it is unclear if it should be erased or error
else unionIsUnsupported
}
else {
Expand Down
2 changes: 1 addition & 1 deletion test/tasty/neg/src-2/TestCompiletimeQuoteType.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TestCompiletimeQuoteType_fail.scala:4: error: can't find type required by type parameter T in class scala.quoted.Type: scala.AnyKind; perhaps it is missing from the classpath.
TestCompiletimeQuoteType_fail.scala:4: error: could not find implicit value for evidence parameter of type scala.quoted.Type[Int]
def test = CompiletimeQuoteType.f[Int]
^
1 error

0 comments on commit 1e5143e

Please sign in to comment.