From b567b8d7321638ef7d4a6be0399d56d07ba10948 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 23 Nov 2017 15:31:55 +0100 Subject: [PATCH 1/2] Make all phantoms unused This removes the necesity of erasing phantoms. This process is done by the erasure of `unused`. --- compiler/src/dotty/tools/dotc/Compiler.scala | 3 +- compiler/src/dotty/tools/dotc/ast/tpd.scala | 1 + .../dotty/tools/dotc/core/Definitions.scala | 8 +-- .../tools/dotc/core/PhantomErasure.scala | 33 ---------- .../src/dotty/tools/dotc/core/Signature.scala | 2 +- .../dotty/tools/dotc/core/TypeErasure.scala | 9 +-- .../tools/dotc/transform/Constructors.scala | 2 +- .../dotty/tools/dotc/transform/Erasure.scala | 28 ++------ .../tools/dotc/transform/FirstTransform.scala | 8 --- .../dotty/tools/dotc/transform/Memoize.scala | 8 +-- .../dotc/transform/SyntheticMethods.scala | 2 +- .../dotc/transform/localopt/Simplify.scala | 5 +- .../src/dotty/tools/dotc/typer/Checking.scala | 8 +-- .../dotty/tools/dotc/FromTastyTests.scala | 29 ++++++++ docs/docs/reference/phantom-types.md | 66 ++++--------------- library/src/dotty/runtime/ErasedPhantom.java | 30 --------- library/src/dotty/runtime/ErasedPhantom.scala | 4 ++ tests/generic-java-signatures/phantom.check | 2 +- tests/generic-java-signatures/phantom.scala | 6 +- .../phantom-overload-2.scala | 14 ++-- .../phantom-overload.scala | 10 +-- tests/neg/phantom-Eq.scala | 14 ++-- tests/neg/phantom-fun-app.scala | 4 +- tests/neg/phantom-in-value-class.scala | 2 +- tests/neg/phantom-multiversal-AndOr.scala | 12 ++-- tests/neg/phantom-multiversal.scala | 6 +- tests/neg/phantom-var-2.scala | 9 +++ tests/neg/phantom-var.scala | 5 +- tests/neg/phantom-volitile.scala | 9 --- tests/neg/reference-phantom-type-2.scala | 11 ++-- tests/pos/phantom-Eq.scala | 14 ++-- tests/pos/phantom-Eq2/Phantom-Eq_1.scala | 14 ++-- tests/pos/phantom-Evidence.scala | 6 +- tests/pos/phantom-in-value-class.scala | 16 ----- tests/pos/reference/phantom-types.scala | 14 ++-- tests/run/phantom-1.scala | 4 +- tests/run/phantom-2.scala | 4 +- tests/run/phantom-3.scala | 4 +- tests/run/phantom-4.scala | 6 +- tests/run/phantom-5.scala | 6 +- tests/run/phantom-OnHList.scala | 6 +- tests/run/phantom-assume-1.scala | 14 ++-- tests/run/phantom-decls-1.scala | 6 +- tests/run/phantom-decls-2.scala | 4 +- tests/run/phantom-decls-3.scala | 4 +- tests/run/phantom-decls-4.scala | 4 +- tests/run/phantom-decls-5.scala | 4 +- tests/run/phantom-erased-methods.scala | 17 +++-- tests/run/phantom-hk-1.scala | 4 +- tests/run/phantom-hk-2.scala | 6 +- tests/run/phantom-in-value-class.scala | 14 ++-- tests/run/phantom-lazy-val-2.check | 3 - tests/run/phantom-lazy-val-2.scala | 31 --------- tests/run/phantom-lazy-val.check | 3 - tests/run/phantom-lazy-val.scala | 21 ------ tests/run/phantom-methods-1.scala | 6 +- tests/run/phantom-methods-10.check | 1 - tests/run/phantom-methods-10.scala | 6 +- tests/run/phantom-methods-11.check | 20 ------ tests/run/phantom-methods-11.scala | 10 +-- tests/run/phantom-methods-12.check | 10 --- tests/run/phantom-methods-12.scala | 8 +-- tests/run/phantom-methods-13.check | 9 --- tests/run/phantom-methods-13.scala | 8 +-- tests/run/phantom-methods-14.scala | 6 +- tests/run/phantom-methods-2.scala | 6 +- tests/run/phantom-methods-3.scala | 6 +- tests/run/phantom-methods-4.scala | 6 +- tests/run/phantom-methods-5.scala | 4 +- tests/run/phantom-methods-6.scala | 4 +- tests/run/phantom-methods-7.scala | 4 +- tests/run/phantom-methods-8.check | 1 - tests/run/phantom-methods-8.scala | 6 +- tests/run/phantom-methods-9.check | 1 - tests/run/phantom-methods-9.scala | 6 +- tests/run/phantom-param-accessor.scala | 7 +- tests/run/phantom-poly-1.scala | 2 +- tests/run/phantom-poly-2.scala | 4 +- tests/run/phantom-poly-3.scala | 4 +- tests/run/phantom-poly-4.scala | 4 +- tests/run/phantom-self-1.scala | 9 +-- tests/run/phantom-val-2.check | 1 - tests/run/phantom-val-2.scala | 10 +-- tests/run/phantom-val.check | 1 - tests/run/phantom-val.scala | 11 ++-- 85 files changed, 267 insertions(+), 493 deletions(-) delete mode 100644 compiler/src/dotty/tools/dotc/core/PhantomErasure.scala delete mode 100644 library/src/dotty/runtime/ErasedPhantom.java create mode 100644 library/src/dotty/runtime/ErasedPhantom.scala create mode 100644 tests/neg/phantom-var-2.scala delete mode 100644 tests/neg/phantom-volitile.scala delete mode 100644 tests/pos/phantom-in-value-class.scala delete mode 100644 tests/run/phantom-lazy-val-2.check delete mode 100644 tests/run/phantom-lazy-val-2.scala delete mode 100644 tests/run/phantom-lazy-val.check delete mode 100644 tests/run/phantom-lazy-val.scala diff --git a/compiler/src/dotty/tools/dotc/Compiler.scala b/compiler/src/dotty/tools/dotc/Compiler.scala index 81399f79ea57..5ff69a5e1314 100644 --- a/compiler/src/dotty/tools/dotc/Compiler.scala +++ b/compiler/src/dotty/tools/dotc/Compiler.scala @@ -80,8 +80,7 @@ class Compiler { new ShortcutImplicits, // Allow implicit functions without creating closures new CrossCastAnd, // Normalize selections involving intersection types. new Splitter) :: // Expand selections involving union types into conditionals - List(new PhantomArgLift, // Extracts the evaluation of phantom arguments placing them before the call. - new UnusedDecls, // Removes all unused defs and vals decls (except for parameters) + List(new UnusedDecls, // Removes all unused defs and vals decls (except for parameters) new VCInlineMethods, // Inlines calls to value class methods new SeqLiterals, // Express vararg arguments as arrays new InterceptedMethods, // Special handling of `==`, `|=`, `getClass` methods diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index d2061204c83a..a16dc7e7cc4e 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -442,6 +442,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { else if (tpw isRef defn.DoubleClass) Literal(Constant(0d)) else if (tpw isRef defn.ByteClass) Literal(Constant(0.toByte)) else if (tpw isRef defn.ShortClass) Literal(Constant(0.toShort)) + else if (tpw.isPhantom) Literal(Constant(null)).withType(tpw) else Literal(Constant(null)).select(defn.Any_asInstanceOf).appliedToType(tpe) } diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 72a69c85431d..09712b629c3a 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -1198,21 +1198,15 @@ class Definitions { val any = enterCompleteClassSymbol(cls, tpnme.Any, Protected | Final | NoInitsTrait, Nil) val nothing = enterCompleteClassSymbol(cls, tpnme.Nothing, Protected | Final | NoInitsTrait, List(any.typeRef)) - enterMethod(cls, nme.assume_, ExprType(nothing.typeRef), Protected | Final | Method) + enterMethod(cls, nme.assume_, ExprType(nothing.typeRef), Protected | Final | Method | Unused) cls } lazy val Phantom_AnyClass = PhantomClass.unforcedDecls.find(_.name eq tpnme.Any).asClass lazy val Phantom_NothingClass = PhantomClass.unforcedDecls.find(_.name eq tpnme.Nothing).asClass - lazy val Phantom_assume = PhantomClass.unforcedDecls.find(_.name eq nme.assume_) /** If the symbol is of the class scala.Phantom.Any or scala.Phantom.Nothing */ def isPhantomTerminalClass(sym: Symbol) = (sym eq Phantom_AnyClass) || (sym eq Phantom_NothingClass) - lazy val ErasedPhantomType: TypeRef = ctx.requiredClassRef("dotty.runtime.ErasedPhantom") - def ErasedPhantomClass(implicit ctx: Context) = ErasedPhantomType.symbol.asClass - - def ErasedPhantom_UNIT(implicit ctx: Context) = ErasedPhantomClass.linkedClass.requiredValue("UNIT") - } diff --git a/compiler/src/dotty/tools/dotc/core/PhantomErasure.scala b/compiler/src/dotty/tools/dotc/core/PhantomErasure.scala deleted file mode 100644 index 0e1e159846f7..000000000000 --- a/compiler/src/dotty/tools/dotc/core/PhantomErasure.scala +++ /dev/null @@ -1,33 +0,0 @@ -package dotty.tools.dotc.core - -import dotty.tools.dotc.ast.tpd._ -import dotty.tools.dotc.core.Contexts.Context -import dotty.tools.dotc.core.Symbols._ -import dotty.tools.dotc.core.Types.Type - -/** Phantom erasure erases: - * - * - Parameters/arguments are removed from the function definition/call in `PhantomArgLift`. - * If the evaluation of the phantom arguments may produce a side effect, these are evaluated and stored in - * local `val`s and then the non phantoms are used in the Apply. Phantom `val`s are then erased to - * `val ev$i: ErasedPhantom = myPhantom` intended to be optimized away by local optimizations. `myPhantom` could be - * a reference to a phantom parameter, a call to Phantom assume or a call to a method that returns a phantom. - * - Definitions of `def`, `val`, `lazy val` and `var` returning a phantom type to return a ErasedPhantom. Where fields - * with ErasedPhantom type are not memoized (see transform/Memoize.scala). - * - Calls to Phantom.assume become calls to ErasedPhantom.UNIT. Intended to be optimized away by local optimizations. - */ -object PhantomErasure { - - /** Returns the default erased type of a phantom type */ - def erasedPhantomType(implicit ctx: Context): Type = defn.ErasedPhantomType - - /** Returns the default erased tree for a call to Phantom.assume */ - def erasedAssume(implicit ctx: Context): Tree = ref(defn.ErasedPhantom_UNIT) - - /** Returns the default erased tree for a phantom parameter ref */ - def erasedParameterRef(implicit ctx: Context): Tree = ref(defn.ErasedPhantom_UNIT) - - /** Is it a pure term inserted by the phantom erasure? */ - def isErasedPhantom(sym: Symbol)(implicit ctx: Context): Boolean = sym eq defn.ErasedPhantom_UNIT - -} diff --git a/compiler/src/dotty/tools/dotc/core/Signature.scala b/compiler/src/dotty/tools/dotc/core/Signature.scala index 12decabbc5dc..43ff835688c5 100644 --- a/compiler/src/dotty/tools/dotc/core/Signature.scala +++ b/compiler/src/dotty/tools/dotc/core/Signature.scala @@ -84,7 +84,7 @@ case class Signature(paramsSig: List[TypeName], resSig: TypeName) { * to the parameter part of this signature. */ def prepend(params: List[Type], isJava: Boolean)(implicit ctx: Context) = - Signature(params.collect { case p if !p.isPhantom => sigName(p, isJava) } ++ paramsSig, resSig) + Signature(params.map(p => sigName(p, isJava)) ++ paramsSig, resSig) /** A signature is under-defined if its paramsSig part contains at least one * `tpnme.Uninstantiated`. Under-defined signatures arise when taking a signature diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index 78568769305a..8685ce78a1a5 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala @@ -380,7 +380,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean else if (semiEraseVCs && isDerivedValueClass(sym)) eraseDerivedValueClassRef(tp) else if (sym == defn.ArrayClass) apply(tp.appliedTo(TypeBounds.empty)) // i966 shows that we can hit a raw Array type. else if (defn.isSyntheticFunctionClass(sym)) defn.erasedFunctionType(sym) - else if (defn.isPhantomTerminalClass(sym)) PhantomErasure.erasedPhantomType + else if (defn.isPhantomTerminalClass(sym)) defn.ErasedPhantomType else if (sym eq defn.PhantomClass) defn.ObjectType // To erase the definitions of Phantom.{assume, Any, Nothing} else eraseNormalClassRef(tp) case tp: AppliedType => @@ -401,10 +401,7 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean case tp: MethodType => def paramErasure(tpToErase: Type) = erasureFn(tp.isJavaMethod, semiEraseVCs, isConstructor, wildcardOK)(tpToErase) - val (names, formals0) = - if (tp.isUnusedMethod) (Nil, Nil) - else if (tp.paramInfos.exists(_.isPhantom)) tp.paramNames.zip(tp.paramInfos).filterNot(_._2.isPhantom).unzip - else (tp.paramNames, tp.paramInfos) + val (names, formals0) = if (tp.isUnusedMethod) (Nil, Nil) else (tp.paramNames, tp.paramInfos) val formals = formals0.mapConserve(paramErasure) eraseResult(tp.resultType) match { case rt: MethodType => @@ -527,8 +524,6 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean } if (defn.isSyntheticFunctionClass(sym)) sigName(defn.erasedFunctionType(sym)) - else if (defn.isPhantomTerminalClass(tp.symbol)) - sigName(PhantomErasure.erasedPhantomType) else normalizeClass(sym.asClass).fullName.asTypeName case tp: AppliedType => diff --git a/compiler/src/dotty/tools/dotc/transform/Constructors.scala b/compiler/src/dotty/tools/dotc/transform/Constructors.scala index 341f916d4593..f90289a5af48 100644 --- a/compiler/src/dotty/tools/dotc/transform/Constructors.scala +++ b/compiler/src/dotty/tools/dotc/transform/Constructors.scala @@ -131,7 +131,7 @@ class Constructors extends MiniPhase with IdentityDenotTransformer { thisPhase = // Produce aligned accessors and constructor parameters. We have to adjust // for any outer parameters, which are last in the sequence of original // parameter accessors but come first in the constructor parameter list. - val accessors = cls.paramAccessors.filterNot(x => x.isSetter || x.info.resultType.classSymbol == defn.ErasedPhantomClass) + val accessors = cls.paramAccessors.filterNot(x => x.isSetter) val vparamsWithOuterLast = vparams match { case vparam :: rest if vparam.name == nme.OUTER => rest ::: vparam :: Nil case _ => vparams diff --git a/compiler/src/dotty/tools/dotc/transform/Erasure.scala b/compiler/src/dotty/tools/dotc/transform/Erasure.scala index 13ec55f6d3b3..0690b6cdfe68 100644 --- a/compiler/src/dotty/tools/dotc/transform/Erasure.scala +++ b/compiler/src/dotty/tools/dotc/transform/Erasure.scala @@ -28,7 +28,6 @@ import ValueClasses._ import TypeUtils._ import ExplicitOuter._ import core.Mode -import core.PhantomErasure import reporting.trace class Erasure extends Phase with DenotTransformer { @@ -213,8 +212,6 @@ object Erasure { val tree1 = if (tree.tpe isRef defn.NullClass) adaptToType(tree, underlying) - else if (wasPhantom(underlying)) - PhantomErasure.erasedParameterRef else if (!(tree.tpe <:< tycon)) { assert(!(tree.tpe.typeSymbol.isPrimitiveValueClass)) val nullTree = Literal(Constant(null)) @@ -437,16 +434,9 @@ object Erasure { } } - if ((origSym eq defn.Phantom_assume) || (origSym.is(Flags.ParamAccessor) && wasPhantom(pt))) - PhantomErasure.erasedAssume - else recur(typed(tree.qualifier, AnySelectionProto)) + recur(typed(tree.qualifier, AnySelectionProto)) } - override def typedIdent(tree: untpd.Ident, pt: Type)(implicit ctx: Context): tpd.Tree = - if (tree.symbol eq defn.Phantom_assume) PhantomErasure.erasedAssume - else if (tree.symbol.is(Flags.Param) && wasPhantom(tree.typeOpt)) PhantomErasure.erasedParameterRef - else super.typedIdent(tree, pt) - override def typedThis(tree: untpd.This)(implicit ctx: Context): Tree = if (tree.symbol == ctx.owner.lexicallyEnclosingClass || tree.symbol.isStaticOwner) promote(tree) else { @@ -507,11 +497,9 @@ object Erasure { .withType(defn.ArrayOf(defn.ObjectType)) args0 = bunchedArgs :: Nil } - // Arguments are phantom if an only if the parameters are phantom, guaranteed by the separation of type lattices - val args1 = args0.filterConserve(arg => !wasPhantom(arg.typeOpt)) - assert(args1 hasSameLengthAs mt.paramInfos) - val args2 = args1.zipWithConserve(mt.paramInfos)(typedExpr) - untpd.cpy.Apply(tree)(fun1, args2) withType mt.resultType + assert(args0 hasSameLengthAs mt.paramInfos) + val args1 = args0.zipWithConserve(mt.paramInfos)(typedExpr) + untpd.cpy.Apply(tree)(fun1, args1) withType mt.resultType case _ => throw new MatchError(i"tree $tree has unexpected type of function ${fun1.tpe.widen}, was ${fun.typeOpt.widen}") } @@ -572,11 +560,6 @@ object Erasure { rhs1 = untpd.Block(paramDefs, rhs1) } vparamss1 = vparamss1.mapConserve(_.filterConserve(!_.symbol.is(Flags.Unused))) - vparamss1 = vparamss1.mapConserve(_.filterConserve(vparam => !wasPhantom(vparam.tpe))) - if (sym.is(Flags.ParamAccessor) && wasPhantom(ddef.tpt.tpe)) { - sym.resetFlag(Flags.ParamAccessor) - rhs1 = PhantomErasure.erasedParameterRef - } val ddef1 = untpd.cpy.DefDef(ddef)( tparams = Nil, vparamss = vparamss1, @@ -703,7 +686,4 @@ object Erasure { def takesBridges(sym: Symbol)(implicit ctx: Context) = sym.isClass && !sym.is(Flags.Trait | Flags.Package) - - private def wasPhantom(tp: Type)(implicit ctx: Context): Boolean = - tp.widenDealias.classSymbol eq defn.ErasedPhantomClass } diff --git a/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala b/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala index cceda89e2976..c0917ac8fb2a 100644 --- a/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala +++ b/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala @@ -161,14 +161,6 @@ class FirstTransform extends MiniPhase with InfoTransformer { thisPhase => } else ddef } - override def transformValDef(vdef: tpd.ValDef)(implicit ctx: Context): tpd.Tree = { - if (vdef.tpt.tpe.isPhantom) { - if (vdef.symbol.is(Mutable)) ctx.error("var fields cannot have Phantom types", vdef.pos) - else if (vdef.symbol.hasAnnotation(defn.VolatileAnnot)) ctx.error("Phantom fields cannot be @volatile", vdef.pos) - } - vdef - } - override def transformStats(trees: List[Tree])(implicit ctx: Context): List[Tree] = ast.Trees.flatten(reorderAndComplete(trees)(ctx.withPhase(thisPhase.next))) diff --git a/compiler/src/dotty/tools/dotc/transform/Memoize.scala b/compiler/src/dotty/tools/dotc/transform/Memoize.scala index 497a229c2748..1f9ffcdf2eba 100644 --- a/compiler/src/dotty/tools/dotc/transform/Memoize.scala +++ b/compiler/src/dotty/tools/dotc/transform/Memoize.scala @@ -107,7 +107,6 @@ import Decorators._ if (sym eq defn.NothingClass) Throw(Literal(Constant(null))) else if (sym eq defn.NullClass) Literal(Constant(null)) else if (sym eq defn.BoxedUnitClass) ref(defn.BoxedUnit_UNIT) - else if (sym eq defn.ErasedPhantomClass) ref(defn.ErasedPhantom_UNIT) else { assert(false, sym + " has no erased bottom tree") EmptyTree @@ -120,11 +119,8 @@ import Decorators._ def adaptToField(tree: Tree): Tree = if (tree.isEmpty) tree else tree.ensureConforms(field.info.widen) - def isErasableBottomField(cls: Symbol): Boolean = { - // TODO: For Scala.js, return false if this field is in a js.Object unless it is an ErasedPhantomClass. - !field.isVolatile && - ((cls eq defn.NothingClass) || (cls eq defn.NullClass) || (cls eq defn.BoxedUnitClass) || (cls eq defn.ErasedPhantomClass)) - } + def isErasableBottomField(cls: Symbol): Boolean = + !field.isVolatile && ((cls eq defn.NothingClass) || (cls eq defn.NullClass) || (cls eq defn.BoxedUnitClass)) if (sym.isGetter) { var rhs = tree.rhs.changeOwnerAfter(sym, field, thisPhase) diff --git a/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala b/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala index 8b9bd364e6d1..9832b6ef63f5 100644 --- a/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala +++ b/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala @@ -163,7 +163,7 @@ class SyntheticMethods(thisPhase: DenotTransformer) { val thatAsClazz = ctx.newSymbol(ctx.owner, nme.x_0, Synthetic, clazzType, coord = ctx.owner.pos) // x$0 def wildcardAscription(tp: Type) = Typed(Underscore(tp), TypeTree(tp)) val pattern = Bind(thatAsClazz, wildcardAscription(clazzType)) // x$0 @ (_: C) - val comparisons = accessors collect { case accessor if !accessor.info.isPhantom => + val comparisons = accessors map { accessor => This(clazz).select(accessor).select(defn.Any_==).appliedTo(ref(thatAsClazz).select(accessor)) } val rhs = // this.x == this$0.x && this.y == x$0.y if (comparisons.isEmpty) Literal(Constant(true)) else comparisons.reduceLeft(_ and _) diff --git a/compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala b/compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala index fe63be6deefb..385ae5f085bc 100644 --- a/compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala +++ b/compiler/src/dotty/tools/dotc/transform/localopt/Simplify.scala @@ -11,7 +11,6 @@ import core.NameOps._ import transform.MegaPhase.MiniPhase import config.Printers.simplify import ast.tpd -import dotty.tools.dotc.core.PhantomErasure import scala.annotation.tailrec @@ -170,8 +169,6 @@ object Simplify { sym.owner.is(CaseClass) && sym.name.isSelectorName && !sym.info.decls.exists(_.is(Mutable | Lazy)) // Conservatively covers case class A(var x: Int) - val isErasedPhantom = PhantomErasure.isErasedPhantom(sym) - - isImmutableGetter || isCaseAccessor || isProductAccessor || isErasedPhantom + isImmutableGetter || isCaseAccessor || isProductAccessor } } diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index c0bd25c13440..ed9c0477364a 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -502,12 +502,10 @@ object Checking { case param :: params => if (param.is(Mutable)) ctx.error(ValueClassParameterMayNotBeAVar(clazz, param), param.pos) - if (param.info.isPhantom) - ctx.error("First parameter of value class must not be phantom", param.pos) - else if (param.is(Unused)) - ctx.error("First parameter of value class cannot be `unused`", param.pos) + if (param.is(Unused)) + ctx.error("value class first parameter cannot be `unused`", param.pos) else { - for (p <- params if !(p.info.isPhantom || p.is(Unused))) + for (p <- params if !p.is(Unused)) ctx.error("value class can only have one non `unused` parameter", p.pos) } case Nil => diff --git a/compiler/test/dotty/tools/dotc/FromTastyTests.scala b/compiler/test/dotty/tools/dotc/FromTastyTests.scala index e48fa73198eb..fe9f2427fcb3 100644 --- a/compiler/test/dotty/tools/dotc/FromTastyTests.scala +++ b/compiler/test/dotty/tools/dotc/FromTastyTests.scala @@ -83,6 +83,9 @@ class FromTastyTests extends ParallelTesting { // Infinite compilation "t3612.scala", + + "phantom-Eq.scala", + "phantom-Evidence.scala", ) ) step1.checkCompile() // Compile all files to generate the class files with tasty @@ -144,6 +147,32 @@ class FromTastyTests extends ParallelTesting { "unused-21.scala", "unused-23.scala", "unused-value-class.scala", + "phantom-methods-12.scala", + "phantom-methods-8.scala", + "phantom-methods-2.scala", + "phantom-methods-9.scala", + "phantom-methods-13.scala", + "phantom-methods-14.scala", + "phantom-decls-4.scala", + "phantom-self-1.scala", + "phantom-val-2.scala", + "phantom-3.scala", + "phantom-OnHList.scala", + "phantom-1.scala", + "phantom-4.scala", + "phantom-5.scala", + "phantom-methods-1.scala", + "phantom-val.scala", + "phantom-decls-2.scala", + "phantom-assume-1.scala", + "phantom-methods-10.scala", + "phantom-methods-7.scala", + "phantom-methods-6.scala", + "phantom-methods-11.scala", + "phantom-erased-methods.scala", + "phantom-methods-5.scala", + "phantom-2.scala", + "phantom-param-accessor.scala", ) ) step1.checkCompile() // Compile all files to generate the class files with tasty diff --git a/docs/docs/reference/phantom-types.md b/docs/docs/reference/phantom-types.md index 9b267815d339..c8e00eb5472c 100644 --- a/docs/docs/reference/phantom-types.md +++ b/docs/docs/reference/phantom-types.md @@ -16,7 +16,7 @@ When saying that they have no effect on the runtime we do not only mean side eff like IO, field mutation, exceptions and so on. We also imply that if a function receives a phantom its result will not be affected by this argument. -As phantoms do not live at runtime they cannot be subtypes of `scala.Any`, which defines +As phantoms do not live at runtime they cannot be subtypes of `scala.Any`, which defines methods such as `hashCode`, `equals`, `getClass`, `asInstanceOf` and `isInstanceOf`. All these operations cannot exist on phantoms as there will not be an underlying object instance at runtime. At first glance this could look like a limitation, but in fact not @@ -49,13 +49,13 @@ In fact we allow multiple phantom universes to exist. +---------+ +-------------------+ +------------------------+ ``` -Inside a universe the full Dotty type system is supported. But we cannot mix types from +Inside a universe the full Dotty type system is supported. But we cannot mix types from different universes with `&`, `|` or in type bounds. Each type must be fully defined in a single universe. Implement your own phantom type ------------------------------- -Phantom types are defined by an `object` extending `scala.Phantom`. This object will represent +Phantom types are defined by an `object` extending `scala.Phantom`. This object will represent a universe of phantom types that is completely separated from types in `scala.Any` or other phantom universes. We can define our phantom universe `MyPhantoms`. @@ -68,7 +68,7 @@ package scala trait Phantom { // only an `object` can extend this trait protected final type Any // not a subtype of scala.Any protected final type Nothing // subtype of every subtype of this.Any - protected final def assume: this.Nothing + protected final unused def assume: this.Nothing } ``` @@ -78,7 +78,7 @@ of the phantom types in `MyPhantoms`, these bounds are `protected` and can not b from outside `MyPhantoms` unless an alias is defined for them. New phantom types can be defined using `type XYZ <: OtherPhantom` (where `>: MyPhantom.Nothing` -will be inferred), this would be the equivalent of `class XYZ extends OtherClass` on types +will be inferred), this would be the equivalent of `class XYZ extends OtherClass` on types only (no runtime definitions). Or aliased with `type MyAny = OtherPhantom`. Within `MyPhantoms` it is possible to refer to `MyPhantoms.Any` and `MyPhantoms.Nothing` with `this.Any` and `this.Nothing` (or just `Any` and `Nothing` but not recommended). Using this we will define @@ -94,7 +94,7 @@ object MyPhantoms extends Phantom { ``` Values of phantom type can be created using the `protected def assume`. This value can be -used as a value of this phantom type as its type is `this.Nothing` (or `MyPhantoms.Nothing`). +used as a value of this phantom type as its type is `this.Nothing` (or `MyPhantoms.Nothing`). Usually this value will be used to define a `implicit def` that returns the phantom with a more precise type. In our example we will only create values of type `Pinky` and `Clyde` @@ -102,8 +102,8 @@ precise type. In our example we will only create values of type `Pinky` and `Cly object MyPhantoms extends Phantom { ... // Type definition - def pinky: Pinky = assume - def clyde: Clyde = assume + unused def pinky: Pinky = assume + unused def clyde: Clyde = assume } ``` @@ -115,8 +115,8 @@ We can look at the following simple application: ```scala import MyPhantoms._ object MyApp { - def run(phantom: Inky) = println("run") - def hide(phantom: Blinky) = println("run") + def run(unused phantom: Inky) = println("run") + def hide(unused phantom: Blinky) = println("run") run(pinky) run(clyde) @@ -134,48 +134,4 @@ mistakes before when compiling the code, no surprises at runtime (hopefully not What happens with Phantoms at runtime? -------------------------------------- -Disclaimer: Most of phantom erasure is implemented, but not all of is has been merged in `dotty/master` yet. - -As phantoms have no effect on the result of a method invocation we just remove them for the call and definition. -The evaluation of the phantom parameter is still done unless it can be optimized away. -By removing them we also restrict overloading as `def f()` and `def f(x: MyPhantom)` will -have the same signature in the bytecode, just use different names to avoid this. - -At runtime the `scala.Phantom` trait will not exist. -* The object extending `Phantom` will not extend it anymore -* All phantom types will be erased on a single erased type (important in overloading for methods returning a phantom) -* Calls to `Phantom.assume` will become a reference to a singleton of the erased phantom type and will be removed wherever possible - -```scala -object MyOtherPhantom extends Phantom { - type MyPhantom <: this.Any - def myPhantom: MyPhantom = assume - - def f1(a: Int, b: MyPhantom, c: Int): Int = a + c - - def f2 = { - f1(3, myPhantom, 2) - } -} -``` - -will be compiled to - -```scala -object MyOtherPhantom { - def myPhantom(): = - - def f1(a: Int, c: Int): Int = a + c - - def f2 = { - val a$ = 3 - myPhantom() - val b$ = 3 - f1(a$, b$) - } -} -``` - -Note that `myPhantom` is not removed as it could have some side effect before returning the phantom. -To remove it just use `inline def myPhantom` instead this will remove the call and allow the -`` to be optimized away. +All phantoms are erased using the `unused` keyword. They will simply not exist at runtime. diff --git a/library/src/dotty/runtime/ErasedPhantom.java b/library/src/dotty/runtime/ErasedPhantom.java deleted file mode 100644 index 98fac71b4304..000000000000 --- a/library/src/dotty/runtime/ErasedPhantom.java +++ /dev/null @@ -1,30 +0,0 @@ -package dotty.runtime; - - -/** Unit type representing an erased phantom value. - * - * Based on implementation of BoxedUnit. - */ -public final class ErasedPhantom implements java.io.Serializable { - private static final long serialVersionUID = 4116021023472525845L; - - public final static ErasedPhantom UNIT = new ErasedPhantom(); - - public final static Class TYPE = java.lang.Void.TYPE; - - private Object readResolve() { return UNIT; } - - private ErasedPhantom() { } - - public boolean equals(java.lang.Object other) { - return this == other; - } - - public int hashCode() { - return 0; - } - - public String toString() { - return "(\uD83D\uDC7B )"; - } -} diff --git a/library/src/dotty/runtime/ErasedPhantom.scala b/library/src/dotty/runtime/ErasedPhantom.scala new file mode 100644 index 000000000000..8aac49a15e3b --- /dev/null +++ b/library/src/dotty/runtime/ErasedPhantom.scala @@ -0,0 +1,4 @@ +package dotty.runtime + +/** Type representing an erased phantom type */ +final abstract class ErasedPhantom diff --git a/tests/generic-java-signatures/phantom.check b/tests/generic-java-signatures/phantom.check index 1efc1bc17904..bf6757ea2b50 100644 --- a/tests/generic-java-signatures/phantom.check +++ b/tests/generic-java-signatures/phantom.check @@ -1,3 +1,3 @@ -public T MyOtherPhantom$.f1(int,int) +public int MyOtherPhantom$.f1(int,int) U <: java.lang.Object T <: dotty.runtime.ErasedPhantom diff --git a/tests/generic-java-signatures/phantom.scala b/tests/generic-java-signatures/phantom.scala index 0c5983253534..c9511bd682d3 100644 --- a/tests/generic-java-signatures/phantom.scala +++ b/tests/generic-java-signatures/phantom.scala @@ -1,11 +1,11 @@ object MyOtherPhantom extends Phantom { type MyPhantom[V] <: this.Any - def myPhantom[X]: MyPhantom[X] = assume + unused def myPhantom[X]: MyPhantom[X] = assume - def f1[U, T <: MyPhantom[U]](a: Int, b: T, c: Int): T = b + def f1[U, T <: MyPhantom[U]](a: Int, c: Int)(unused b: T): Int = a def f2 = { - f1(3, myPhantom[Int], 2) + f1(3 ,2)(myPhantom[Int]) } } diff --git a/tests/neg-custom-args/allow-double-bindings/phantom-overload-2.scala b/tests/neg-custom-args/allow-double-bindings/phantom-overload-2.scala index 5f7dda4d4fb3..0f2710b873ba 100644 --- a/tests/neg-custom-args/allow-double-bindings/phantom-overload-2.scala +++ b/tests/neg-custom-args/allow-double-bindings/phantom-overload-2.scala @@ -3,15 +3,15 @@ class phantomOverload2 { import Boo._ def foo1() = ??? - def foo1(x: A) = ??? // error - def foo1(x1: B)(x2: N) = ??? // error + def foo1(unused x: A) = ??? // error + def foo1(unused x1: B)(unused x2: N) = ??? // error - def foo2(x1: Int, x2: A) = ??? - def foo2(x1: A)(x2: Int) = ??? // error - def foo2(x1: N)(x2: A)(x3: Int) = ??? // error + def foo2(x1: Int)(unused x2: A) = ??? + def foo2(unused x1: A)(x2: Int) = ??? // error + def foo2(unused x1: N)(unused x2: A)(x3: Int) = ??? // error - def foo3(x1: Int, x2: A) = ??? - def foo3(x1: Int, x2: A)(x3: A) = ??? // error + def foo3(unused x1: Int, x2: A) = ??? + def foo3(unused x1: Int, x2: A)(unused x3: A) = ??? // error } object Boo extends Phantom { diff --git a/tests/neg-custom-args/allow-double-bindings/phantom-overload.scala b/tests/neg-custom-args/allow-double-bindings/phantom-overload.scala index d4de97c7bbd3..0d6eab761c71 100644 --- a/tests/neg-custom-args/allow-double-bindings/phantom-overload.scala +++ b/tests/neg-custom-args/allow-double-bindings/phantom-overload.scala @@ -8,11 +8,11 @@ class phantomOverload { def foo1(): C = nothing2 // error def foo1(): N = nothing // error - def foo2(x: A) = ??? - def foo2(x: A) = ??? // error - def foo2(x: B) = ??? // error - def foo2(x: C) = ??? // error - def foo2(x: N) = ??? // error + def foo2(unused x: A) = ??? + def foo2(unused x: A) = ??? // error + def foo2(unused x: B) = ??? // error + def foo2(unused x: C) = ??? // error + def foo2(unused x: N) = ??? // error } object Boo extends Phantom { diff --git a/tests/neg/phantom-Eq.scala b/tests/neg/phantom-Eq.scala index 6d4fcb653260..e18e9f1701be 100644 --- a/tests/neg/phantom-Eq.scala +++ b/tests/neg/phantom-Eq.scala @@ -23,16 +23,16 @@ object EqUtil extends Phantom { type PhantomEqEq[T] = PhantomEq[T, T] implicit class EqualsDeco[T](val x: T) extends AnyVal { - def ===[U] (y: U)(implicit ce: PhantomEq[T, U]) = x.equals(y) + def ===[U] (y: U)(implicit unused ce: PhantomEq[T, U]) = x.equals(y) } - implicit def eqString: PhantomEqEq[String] = assume - implicit def eqInt: PhantomEqEq[Int] = assume - implicit def eqDouble: PhantomEqEq[Double] = assume + implicit unused def eqString: PhantomEqEq[String] = assume + implicit unused def eqInt: PhantomEqEq[Int] = assume + implicit unused def eqDouble: PhantomEqEq[Double] = assume - implicit def eqByteNum: PhantomEq[Byte, Number] = assume - implicit def eqNumByte: PhantomEq[Number, Byte] = assume + implicit unused def eqByteNum: PhantomEq[Byte, Number] = assume + implicit unused def eqNumByte: PhantomEq[Number, Byte] = assume - implicit def eqSeq[T, U](implicit eq: PhantomEq[T, U]): PhantomEq[Seq[T], Seq[U]] = assume + implicit unused def eqSeq[T, U](implicit eq: PhantomEq[T, U]): PhantomEq[Seq[T], Seq[U]] = assume } diff --git a/tests/neg/phantom-fun-app.scala b/tests/neg/phantom-fun-app.scala index 4e6e4424acec..1c403da61806 100644 --- a/tests/neg/phantom-fun-app.scala +++ b/tests/neg/phantom-fun-app.scala @@ -2,8 +2,8 @@ class phantomFunApp { import Boo._ // Note: this is dangerous as it imports Boo.Any as Any - def foo1(a: Any) = ??? - def foo2(b: BooAny) = ??? + def foo1(unused a: Any) = ??? + def foo2(unused b: BooAny) = ??? foo1(1) foo1(boo[Blinky]) // error diff --git a/tests/neg/phantom-in-value-class.scala b/tests/neg/phantom-in-value-class.scala index 23f225767f41..c154f8d7582e 100644 --- a/tests/neg/phantom-in-value-class.scala +++ b/tests/neg/phantom-in-value-class.scala @@ -1,7 +1,7 @@ import MyPhantom._ -class Cursed1(val p: Boo) extends AnyVal // error +class Cursed1(unused val p: Boo) extends AnyVal // error class Cursed2(val n: Int)(val a: Int) extends AnyVal // error diff --git a/tests/neg/phantom-multiversal-AndOr.scala b/tests/neg/phantom-multiversal-AndOr.scala index 9fc8ff8bc6df..c7ff53ae01be 100644 --- a/tests/neg/phantom-multiversal-AndOr.scala +++ b/tests/neg/phantom-multiversal-AndOr.scala @@ -3,13 +3,13 @@ class BooFunDef1 { import Universe1._ import UniverseA._ - def fun1(b: One | A) = ??? // error - def fun2(b: A | One) = ??? // error - def fun3(b: A | One | Any) = ??? // error // error + def fun1(unused b: One | A) = ??? // error + def fun2(unused b: A | One) = ??? // error + def fun3(unused b: A | One | Any) = ??? // error // error - def fun4(b: A & One) = ??? // error - def fun5(b: One & A) = ??? // error - def fun6(b: A & One & Any) = ??? // error // error + def fun4(unused b: A & One) = ??? // error + def fun5(unused b: One & A) = ??? // error + def fun6(unused b: A & One & Any) = ??? // error // error } object Universe1 extends Phantom { diff --git a/tests/neg/phantom-multiversal.scala b/tests/neg/phantom-multiversal.scala index af1571033e8f..5164fc21e2a5 100644 --- a/tests/neg/phantom-multiversal.scala +++ b/tests/neg/phantom-multiversal.scala @@ -15,9 +15,9 @@ class BooFunDef1 { funMulti(a, b, 42) // error funMulti(one, two, one) // error // error - def fun1(x: One, y: Two) = ??? - def funA(k: A, l: B) = ??? - def funMulti(k: A, x: One, i: Int) = ??? + def fun1(unused x: One, y: Two) = ??? + def funA(unused k: A, l: B) = ??? + def funMulti(unused k: A, x: One, i: Int) = ??? } object Universe1 extends Phantom { diff --git a/tests/neg/phantom-var-2.scala b/tests/neg/phantom-var-2.scala new file mode 100644 index 000000000000..8db8fd6fe768 --- /dev/null +++ b/tests/neg/phantom-var-2.scala @@ -0,0 +1,9 @@ + +class Foo { + unused var foo = Boo.boo // error +} + +object Boo extends Phantom { + type A <: this.Any + unused def boo: A = assume +} diff --git a/tests/neg/phantom-var.scala b/tests/neg/phantom-var.scala index 5a7e2db3fdb6..13647f72a0af 100644 --- a/tests/neg/phantom-var.scala +++ b/tests/neg/phantom-var.scala @@ -1,8 +1,9 @@ class Foo { - var foo = Boo.boo // error: var fields cannot have Phantom types + var foo = Boo.boo // error } object Boo extends Phantom { - def boo = assume + type A <: this.Any + unused def boo: A = assume } diff --git a/tests/neg/phantom-volitile.scala b/tests/neg/phantom-volitile.scala deleted file mode 100644 index e8874c035503..000000000000 --- a/tests/neg/phantom-volitile.scala +++ /dev/null @@ -1,9 +0,0 @@ - -class Foo { - @volatile var foo1 = Boo.boo // error: var fields cannot have Phantom types - @volatile val foo2 = Boo.boo // error: Phantom fields cannot be @volatile -} - -object Boo extends Phantom { - def boo = assume -} diff --git a/tests/neg/reference-phantom-type-2.scala b/tests/neg/reference-phantom-type-2.scala index 3bd7cbcb422f..f4c73a601d61 100644 --- a/tests/neg/reference-phantom-type-2.scala +++ b/tests/neg/reference-phantom-type-2.scala @@ -4,17 +4,18 @@ object MyPhantoms extends Phantom { type Pinky <: Inky type Clyde <: Pinky - def pinky: Pinky = assume - def clyde: Clyde = assume + unused def pinky: Pinky = assume + unused def clyde: Clyde = assume } import MyPhantoms._ object MyApp { - def run(phantom: Inky) = println("run") - def hide(phantom: Blinky) = println("run") + def run(unused phantom: Inky) = println("run") + def hide(unused phantom: Blinky) = println("run") run(pinky) run(clyde) - hide(null.asInstanceOf[Blinky]) // error + val a: Blinky = null.asInstanceOf[Blinky] // error + hide(a) } diff --git a/tests/pos/phantom-Eq.scala b/tests/pos/phantom-Eq.scala index 6ed38a4ff05e..a957d7ef91e7 100644 --- a/tests/pos/phantom-Eq.scala +++ b/tests/pos/phantom-Eq.scala @@ -18,15 +18,15 @@ object EqUtil extends Phantom { type PhantomEqEq[T] = PhantomEq[T, T] implicit class EqualsDeco[T](val x: T) extends AnyVal { - def ===[U] (y: U)(implicit ce: PhantomEq[T, U]) = x.equals(y) + def ===[U] (y: U)(implicit unused ce: PhantomEq[T, U]) = x.equals(y) } - implicit def eqString: PhantomEqEq[String] = assume - implicit def eqInt: PhantomEqEq[Int] = assume - implicit def eqDouble: PhantomEqEq[Double] = assume + implicit unused def eqString: PhantomEqEq[String] = assume + implicit unused def eqInt: PhantomEqEq[Int] = assume + implicit unused def eqDouble: PhantomEqEq[Double] = assume - implicit def eqByteNum: PhantomEq[Byte, Number] = assume - implicit def eqNumByte: PhantomEq[Number, Byte] = assume + implicit unused def eqByteNum: PhantomEq[Byte, Number] = assume + implicit unused def eqNumByte: PhantomEq[Number, Byte] = assume - implicit def eqSeq[T, U](implicit eq: PhantomEq[T, U]): PhantomEq[Seq[T], Seq[U]] = assume + implicit unused def eqSeq[T, U](implicit unused eq: PhantomEq[T, U]): PhantomEq[Seq[T], Seq[U]] = assume } diff --git a/tests/pos/phantom-Eq2/Phantom-Eq_1.scala b/tests/pos/phantom-Eq2/Phantom-Eq_1.scala index 3d03c64e63a1..2fd73af56fc6 100644 --- a/tests/pos/phantom-Eq2/Phantom-Eq_1.scala +++ b/tests/pos/phantom-Eq2/Phantom-Eq_1.scala @@ -6,15 +6,15 @@ object EqUtil extends Phantom { type PhantomEqEq[T] = PhantomEq[T, T] implicit class EqualsDeco[T](val x: T) extends AnyVal { - def ===[U] (y: U)(implicit ce: PhantomEq[T, U]) = x.equals(y) + def ===[U] (y: U)(implicit unused ce: PhantomEq[T, U]) = x.equals(y) } - implicit def eqString: PhantomEqEq[String] = assume - implicit def eqInt: PhantomEqEq[Int] = assume - implicit def eqDouble: PhantomEqEq[Double] = assume + implicit unused def eqString: PhantomEqEq[String] = assume + implicit unused def eqInt: PhantomEqEq[Int] = assume + implicit unused def eqDouble: PhantomEqEq[Double] = assume - implicit def eqByteNum: PhantomEq[Byte, Number] = assume - implicit def eqNumByte: PhantomEq[Number, Byte] = assume + implicit unused def eqByteNum: PhantomEq[Byte, Number] = assume + implicit unused def eqNumByte: PhantomEq[Number, Byte] = assume - implicit def eqSeq[T, U](implicit eq: PhantomEq[T, U]): PhantomEq[Seq[T], Seq[U]] = assume + implicit unused def eqSeq[T, U](implicit unused eq: PhantomEq[T, U]): PhantomEq[Seq[T], Seq[U]] = assume } diff --git a/tests/pos/phantom-Evidence.scala b/tests/pos/phantom-Evidence.scala index dd84f2c08383..98f9c08c3b13 100644 --- a/tests/pos/phantom-Evidence.scala +++ b/tests/pos/phantom-Evidence.scala @@ -10,8 +10,8 @@ object WithNormalState { def newInstance(): Instance[Off] = new Instance[Off] } class Instance[S <: State] private { - def getOnInstance(implicit ev: S =::= Off): Instance[On] = new Instance[On] // phantom parameter ev is erased - def getOffInstance(implicit ev: S =::= On): Instance[Off] = new Instance[Off] // phantom parameter ev is erased + def getOnInstance(implicit unused ev: S =::= Off): Instance[On] = new Instance[On] // phantom parameter ev is erased + def getOffInstance(implicit unused ev: S =::= On): Instance[Off] = new Instance[Off] // phantom parameter ev is erased } def run() = { @@ -24,5 +24,5 @@ object WithNormalState { object Utils extends Phantom { type =::=[From, To] <: this.Any - implicit def tpEquals[A]: A =::= A = assume + implicit unused def tpEquals[A]: A =::= A = assume } diff --git a/tests/pos/phantom-in-value-class.scala b/tests/pos/phantom-in-value-class.scala deleted file mode 100644 index 8714cc50c37c..000000000000 --- a/tests/pos/phantom-in-value-class.scala +++ /dev/null @@ -1,16 +0,0 @@ - -object PhantomInValueClass { - import BooUtil._ - new VC("ghi").foo(boo) -} - -object BooUtil extends Phantom { - - type Boo <: this.Any - def boo: Boo = assume - - class VC[T](val x: T) extends AnyVal { - def foo(b: Boo) = println(x) - } - -} diff --git a/tests/pos/reference/phantom-types.scala b/tests/pos/reference/phantom-types.scala index 81c4815b02d0..d30d94201ece 100644 --- a/tests/pos/reference/phantom-types.scala +++ b/tests/pos/reference/phantom-types.scala @@ -4,14 +4,14 @@ object MyPhantoms extends Phantom { type Pinky <: Inky type Clyde <: Pinky - def pinky: Pinky = assume - def clyde: Clyde = assume + unused def pinky: Pinky = assume + unused def clyde: Clyde = assume } import MyPhantoms._ object MyApp { - def run(phantom: Inky) = println("run") - def hide(phantom: Blinky) = println("run") + def run(unused phantom: Inky) = println("run") + def hide(unused phantom: Blinky) = println("run") run(pinky) run(clyde) @@ -19,11 +19,11 @@ object MyApp { object MyOtherPhantom extends Phantom { type MyPhantom <: this.Any - def myPhantom: MyPhantom = assume + unused def myPhantom: MyPhantom = assume - def f1(a: Int, b: MyPhantom, c: Int): Int = a + c + def f1(a: Int, b: Int)(unused c: MyPhantom): Int = a + b def f2 = { - f1(3, myPhantom, 2) + f1(3, 2)(myPhantom) } } diff --git a/tests/run/phantom-1.scala b/tests/run/phantom-1.scala index 7c5a5ecb6929..3c42bf16460e 100644 --- a/tests/run/phantom-1.scala +++ b/tests/run/phantom-1.scala @@ -5,12 +5,12 @@ object Test { fun1(Boo.any) } - def fun1(boo: BooAny): Unit = { + def fun1(unused boo: BooAny): Unit = { println("fun1") } } object Boo extends Phantom { type BooAny = this.Any - def any: BooAny = assume + unused def any: BooAny = assume } diff --git a/tests/run/phantom-2.scala b/tests/run/phantom-2.scala index a29012281921..8d23ea35d2df 100644 --- a/tests/run/phantom-2.scala +++ b/tests/run/phantom-2.scala @@ -5,12 +5,12 @@ object Test { fun2(Boo.nothig) } - def fun2(bottom: BooNothing): Unit = { + def fun2(unused bottom: BooNothing): Unit = { println("fun2") } } object Boo extends Phantom { type BooNothing = this.Nothing - def nothig: BooNothing = assume + unused def nothig: BooNothing = assume } diff --git a/tests/run/phantom-3.scala b/tests/run/phantom-3.scala index aaac8bd2953f..2e27431e5423 100644 --- a/tests/run/phantom-3.scala +++ b/tests/run/phantom-3.scala @@ -7,7 +7,7 @@ object Test { fun3(boo[Pinky], boo[Casper]) } - def fun3(x1: Blinky, x2: Inky): Unit = { + def fun3(unused x1: Blinky, x2: Inky): Unit = { println("fun3") } } @@ -17,5 +17,5 @@ object Boo extends Phantom { type Inky <: Blinky type Pinky <: Inky type Casper = Pinky - def boo[B <: Blinky]: B = assume + unused def boo[B <: Blinky]: B = assume } diff --git a/tests/run/phantom-4.scala b/tests/run/phantom-4.scala index d89592af1cfc..099df17966d4 100644 --- a/tests/run/phantom-4.scala +++ b/tests/run/phantom-4.scala @@ -1,13 +1,13 @@ object Test { import Boo._ - + def main(args: Array[String]): Unit = { fun4(3, 4, boo[Blinky], boo[Pinky]) fun4(5, 6, boo[Inky], boo[Pinky]) fun4(7, 8, boo[Pinky], boo[Casper]) } - def fun4(n: Int, n2: Int, top: Blinky, bottom: Pinky): Unit = { + def fun4(unused n: Int, n2: Int, top: Blinky, bottom: Pinky): Unit = { println("fun4") } @@ -18,5 +18,5 @@ object Boo extends Phantom { type Inky <: Blinky type Pinky <: Inky type Casper = Pinky - def boo[B <: Blinky]: B = assume + unused def boo[B <: Blinky]: B = assume } diff --git a/tests/run/phantom-5.scala b/tests/run/phantom-5.scala index 85fd49453692..9a900a7e972c 100644 --- a/tests/run/phantom-5.scala +++ b/tests/run/phantom-5.scala @@ -1,13 +1,13 @@ object Test { import Boo._ - + def main(args: Array[String]): Unit = { fun5(boo[Blinky])(15)(boo[Pinky])(16) fun5(boo[Inky])(17)(boo[Pinky])(18) fun5(boo[Pinky])(19)(boo[Casper])(20) } - def fun5(top: Blinky)(n: Int)(bottom: Clyde)(n2: Int): Unit = { + def fun5(unused top: Blinky)(n: Int)(unused bottom: Clyde)(n2: Int): Unit = { println("fun5") } } @@ -18,5 +18,5 @@ object Boo extends Phantom { type Pinky <: Inky type Clyde >: Pinky <: Inky type Casper = Pinky - def boo[B <: Blinky]: B = assume + unused def boo[B <: Blinky]: B = assume } diff --git a/tests/run/phantom-OnHList.scala b/tests/run/phantom-OnHList.scala index 0990479cd57c..c27818199612 100644 --- a/tests/run/phantom-OnHList.scala +++ b/tests/run/phantom-OnHList.scala @@ -77,7 +77,7 @@ trait Appender[L1 <: HList, L2 <: HList] { } object Appender { - implicit def lowLevelAppender[L1 <: HList, L2 <: HList, O <: HList](implicit p: PhantomAppender.Aux[L1, L2, O]): Appender[L1, L2] { type Out = O } = + implicit def lowLevelAppender[L1 <: HList, L2 <: HList, O <: HList](implicit unused p: PhantomAppender.Aux[L1, L2, O]): Appender[L1, L2] { type Out = O } = new Appender[L1, L2] { type Out = O def apply(l1: L1, l2: L2): Out = HListN(Array.concat(l1.underlying, l2.underlying)).asInstanceOf[O] @@ -88,6 +88,6 @@ object Appender { object PhantomAppender extends Phantom { type Aux[L1 <: HList, L2 <: HList, O <: HList] <: this.Any - implicit def caseHNil[L <: HList]: Aux[HNil, L, L] = assume - implicit def caseHCons[H, T <: HList, L <: HList, O <: HList](implicit p: Aux[T, L, O]): Aux[H :: T, L, H :: O] = assume + implicit unused def caseHNil[L <: HList]: Aux[HNil, L, L] = assume + implicit unused def caseHCons[H, T <: HList, L <: HList, O <: HList](implicit unused p: Aux[T, L, O]): Aux[H :: T, L, H :: O] = assume } diff --git a/tests/run/phantom-assume-1.scala b/tests/run/phantom-assume-1.scala index bf7efe9d4546..adfb253da70d 100644 --- a/tests/run/phantom-assume-1.scala +++ b/tests/run/phantom-assume-1.scala @@ -3,15 +3,17 @@ object Test { import Boo._ def main(args: Array[String]): Unit = { - Boo.assume1 - Boo.assume2 - Boo.assume3 + foo(Boo.assume1) + foo(Boo.assume2) + foo(Boo.assume3) } + + def foo(unused x: Boo.BooAny) = () } object Boo extends Phantom { type BooAny = this.Any - def assume1: BooAny = assume - def assume2: BooAny = this.assume - def assume3: BooAny = Boo.assume + unused def assume1: BooAny = assume + unused def assume2: BooAny = this.assume + unused def assume3: BooAny = Boo.assume } diff --git a/tests/run/phantom-decls-1.scala b/tests/run/phantom-decls-1.scala index 8faedbdc1a9a..5dd661d054fa 100644 --- a/tests/run/phantom-decls-1.scala +++ b/tests/run/phantom-decls-1.scala @@ -6,11 +6,11 @@ object Test { new Boo1[BooAny]().polyfun1(boo[Inky]) } - def fun(top: BooAny): Unit = () + def fun(unused top: BooAny): Unit = () class Boo1[P <: BooAny] { println("Boo1") - def polyfun1(p1: P): Unit = { + def polyfun1(unused p1: P): Unit = { println("Boo1.polyfun1") } } @@ -20,5 +20,5 @@ object Boo extends Phantom { type BooAny = this.Any type Blinky <: this.Any type Inky <: Blinky - def boo[B <: Blinky]: B = assume + unused def boo[B <: Blinky]: B = assume } diff --git a/tests/run/phantom-decls-2.scala b/tests/run/phantom-decls-2.scala index f5fe9c46f09c..fd61a990affd 100644 --- a/tests/run/phantom-decls-2.scala +++ b/tests/run/phantom-decls-2.scala @@ -10,7 +10,7 @@ object Test { class Boo2 { println("Boo2") type Boo3 = BooAny - def polyfun1(p2: Boo3): Unit = { + def polyfun1(unused p2: Boo3): Unit = { println("Boo2.polyfun1") } } @@ -22,5 +22,5 @@ object Boo extends Phantom { type Inky <: Blinky type Pinky <: Inky type Casper = Pinky - def boo[B <: this.Any]: B = assume + unused def boo[B <: this.Any]: B = assume } diff --git a/tests/run/phantom-decls-3.scala b/tests/run/phantom-decls-3.scala index 5fb0bb90baa8..b3834126c0b5 100644 --- a/tests/run/phantom-decls-3.scala +++ b/tests/run/phantom-decls-3.scala @@ -16,7 +16,7 @@ object Test { trait Boo3 { println("Boo3") type Boo1 <: BooAny - def polyfun1(p3: Boo1): Unit = { + def polyfun1(unused p3: Boo1): Unit = { println("Boo3.polyfun1") } } @@ -27,5 +27,5 @@ object Boo extends Phantom { type Blinky <: this.Any type Inky <: Blinky type Pinky <: Inky - def boo[B <: BooAny]: B = assume + unused def boo[B <: BooAny]: B = assume } diff --git a/tests/run/phantom-decls-4.scala b/tests/run/phantom-decls-4.scala index 696636415a0a..a579c75061cf 100644 --- a/tests/run/phantom-decls-4.scala +++ b/tests/run/phantom-decls-4.scala @@ -7,7 +7,7 @@ object Test { new Boo4(boo[Pinky]) } - class Boo4(p4: Blinky) { + class Boo4(unused p4: Blinky) { println("Boo4") } } @@ -16,5 +16,5 @@ object Boo extends Phantom { type Blinky <: this.Any type Inky <: Blinky type Pinky <: Inky - def boo[B <: Blinky]: B = assume + unused def boo[B <: Blinky]: B = assume } diff --git a/tests/run/phantom-decls-5.scala b/tests/run/phantom-decls-5.scala index 7392fcbdd63e..26f5f8270d93 100644 --- a/tests/run/phantom-decls-5.scala +++ b/tests/run/phantom-decls-5.scala @@ -6,7 +6,7 @@ object Test { new Boo5[Pinky](boo[Pinky]) } - class Boo5[P <: Blinky](p5: P) { + class Boo5[P <: Blinky](unused p5: P) { println("Boo5") } } @@ -15,5 +15,5 @@ object Boo extends Phantom { type Blinky <: this.Any type Inky <: Blinky type Pinky <: Inky - def boo[B <: Blinky]: B = assume + unused def boo[B <: Blinky]: B = assume } diff --git a/tests/run/phantom-erased-methods.scala b/tests/run/phantom-erased-methods.scala index 161dc2c85336..cc37cfa2d84c 100644 --- a/tests/run/phantom-erased-methods.scala +++ b/tests/run/phantom-erased-methods.scala @@ -1,5 +1,3 @@ -import dotty.runtime.ErasedPhantom - object Test { import Boo._ @@ -11,18 +9,23 @@ object Test { foo.getClass.getDeclaredMethod("fun1") foo.getClass.getDeclaredMethod("fun2", classOf[String]) - assert(foo.getClass.getDeclaredMethod("fun3").getReturnType == classOf[ErasedPhantom]) + try { + foo.getClass.getDeclaredMethod("fun3") + assert(false) + } catch { + case _: NoSuchMethodException => // OK + } } } class Foo { import Boo._ - def fun1(b: BooAny): Unit = () - def fun2(b: BooAny, s: String): Unit = () - def fun3(): BooAny = boo + def fun1(unused b: BooAny): Unit = () + def fun2(unused b: BooAny)(s: String): Unit = () + unused def fun3(): BooAny = boo } object Boo extends Phantom { type BooAny = Boo.Any - def boo: BooAny = assume + unused def boo: BooAny = assume } diff --git a/tests/run/phantom-hk-1.scala b/tests/run/phantom-hk-1.scala index bcf1c68012c2..f1e688533b43 100644 --- a/tests/run/phantom-hk-1.scala +++ b/tests/run/phantom-hk-1.scala @@ -10,7 +10,7 @@ object Test { type HKPhantom[X <: Blinky] = X - def hkFun1[Y <: Blinky](p9: HKPhantom[Y]) = { + def hkFun1[Y <: Blinky](unused p9: HKPhantom[Y]) = { println("hkFun1") } @@ -23,5 +23,5 @@ object Boo extends Phantom { type Blinky <: this.Any type Inky <: Blinky type Pinky <: Inky - def boo[B <: this.Any]: B = assume + unused def boo[B <: this.Any]: B = assume } diff --git a/tests/run/phantom-hk-2.scala b/tests/run/phantom-hk-2.scala index 3483e5a4b11a..342515c0da63 100644 --- a/tests/run/phantom-hk-2.scala +++ b/tests/run/phantom-hk-2.scala @@ -9,9 +9,9 @@ object Test { fun(hkFun2(boo[Pinky])) } - def fun(top: BooAny): Unit = println("hk2") + def fun(unused top: BooAny): Unit = println("hk2") - def hkFun2[Y <: BooAny](p10: HKPhantom[Y]): HKPhantom[Y] = p10 + unused def hkFun2[Y <: BooAny](unused p10: HKPhantom[Y]): HKPhantom[Y] = p10 } @@ -20,5 +20,5 @@ object Boo extends Phantom { type Blinky <: Boo.Any type Inky <: Blinky type Pinky <: Inky - def boo[B <: Boo.Any]: B = assume + unused def boo[B <: Boo.Any]: B = assume } diff --git a/tests/run/phantom-in-value-class.scala b/tests/run/phantom-in-value-class.scala index daa93a5b31a5..de4f84ea5e7b 100644 --- a/tests/run/phantom-in-value-class.scala +++ b/tests/run/phantom-in-value-class.scala @@ -4,19 +4,21 @@ object Test { def main(args: Array[String]): Unit = { val cursed = new Cursed(7)(boo) val cursed2 = new Cursed(7)(boo) - cursed.p - cursed2.p + foo(cursed.p) + foo(cursed2.p) } + + def foo(unused x: Boo) = () } -class Cursed(val n: Int)(val p: Boo) extends AnyVal +class Cursed(val n: Int)(unused val p: Boo) extends AnyVal -class Cursed2[B <: Boo](val n: Int)(val p: B) extends AnyVal +class Cursed2[B <: Boo](val n: Int)(unused val p: B) extends AnyVal -class Cursed3[B <: Boo](val n: Int)(val p1: Boo, val p2: B) extends AnyVal +class Cursed3[B <: Boo](val n: Int)(unused val p1: Boo, val p2: B) extends AnyVal object MyPhantom extends Phantom { type Boo <: super[MyPhantom].Any - def boo: Boo = assume + unused def boo: Boo = assume } diff --git a/tests/run/phantom-lazy-val-2.check b/tests/run/phantom-lazy-val-2.check deleted file mode 100644 index 069e33cfba04..000000000000 --- a/tests/run/phantom-lazy-val-2.check +++ /dev/null @@ -1,3 +0,0 @@ -1 -foo -2 diff --git a/tests/run/phantom-lazy-val-2.scala b/tests/run/phantom-lazy-val-2.scala deleted file mode 100644 index 490c3a4113aa..000000000000 --- a/tests/run/phantom-lazy-val-2.scala +++ /dev/null @@ -1,31 +0,0 @@ - -object Test { - - def main(args: Array[String]): Unit = { - val f = new Foo - println(1) - f.foo - println(2) - f.foo - - // TODO: Erase - // Currently not erasing fields for lazy vals - assert(f.getClass.getDeclaredFields.exists(_.getName.startsWith("foo")), "Field foo erased. Optimized accidentally?") - } - - -} - -class Foo { - import Boo._ - - lazy val foo = { - println("foo") - any - } -} - -object Boo extends Phantom { - type BooAny = this.Any - def any: BooAny = assume -} diff --git a/tests/run/phantom-lazy-val.check b/tests/run/phantom-lazy-val.check deleted file mode 100644 index 069e33cfba04..000000000000 --- a/tests/run/phantom-lazy-val.check +++ /dev/null @@ -1,3 +0,0 @@ -1 -foo -2 diff --git a/tests/run/phantom-lazy-val.scala b/tests/run/phantom-lazy-val.scala deleted file mode 100644 index 0aca381d3059..000000000000 --- a/tests/run/phantom-lazy-val.scala +++ /dev/null @@ -1,21 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - println(1) - foo - println(2) - foo - } - - lazy val foo = { - println("foo") - any - } - -} - -object Boo extends Phantom { - type BooAny = this.Any - def any: BooAny = assume -} diff --git a/tests/run/phantom-methods-1.scala b/tests/run/phantom-methods-1.scala index 4888974c8e77..1d835d588336 100644 --- a/tests/run/phantom-methods-1.scala +++ b/tests/run/phantom-methods-1.scala @@ -5,13 +5,13 @@ object Test { fun(phantomFun1()) } - def fun(top: BooAny): Unit = () + def fun(unused top: BooAny): Unit = () - def phantomFun1(): Pinky = boo[Pinky] + unused def phantomFun1(): Pinky = boo[Pinky] } object Boo extends Phantom { type BooAny = Boo.Any type Pinky <: Boo.Any - def boo[B <: Boo.Any]: B = assume + unused def boo[B <: Boo.Any]: B = assume } diff --git a/tests/run/phantom-methods-10.check b/tests/run/phantom-methods-10.check index 50cb66f41e35..5353be80d1af 100644 --- a/tests/run/phantom-methods-10.check +++ b/tests/run/phantom-methods-10.check @@ -1,3 +1,2 @@ fun -inky pacFun4 diff --git a/tests/run/phantom-methods-10.scala b/tests/run/phantom-methods-10.scala index 41b8ece4f827..c521aba22736 100644 --- a/tests/run/phantom-methods-10.scala +++ b/tests/run/phantom-methods-10.scala @@ -5,11 +5,11 @@ object Test { fun2.pacFun4(inky) } - def pacFun4(clyde: Inky) = { + def pacFun4(unused clyde: Inky) = { println("pacFun4") } - def inky: Inky = { + unused def inky: Inky = { println("inky") boo[Inky] } @@ -22,5 +22,5 @@ object Test { object Boo extends Phantom { type Inky <: this.Any - def boo[B <: this.Any]: B = assume + unused def boo[B <: this.Any]: B = assume } diff --git a/tests/run/phantom-methods-11.check b/tests/run/phantom-methods-11.check index fcaa59464f2f..de1491a338a6 100644 --- a/tests/run/phantom-methods-11.check +++ b/tests/run/phantom-methods-11.check @@ -1,26 +1,6 @@ -x1 -x2 -x3 -x4 -x5 fun -y1 -y2 -y3 -y4 -y5 Fun Fun2 -z1 -z2 -z3 -z4 -z5 Fun2fun Fun2 -w1 -w2 -w3 -w4 -w5 Fun2fun2 diff --git a/tests/run/phantom-methods-11.scala b/tests/run/phantom-methods-11.scala index 10b15b8d7d09..7045ac65b837 100644 --- a/tests/run/phantom-methods-11.scala +++ b/tests/run/phantom-methods-11.scala @@ -43,21 +43,21 @@ object Test { ) } - def fun(x1: Inky, x2: Inky)(x3: Inky)(x4: Inky, x5: Inky) = { + def fun(unused x1: Inky, x2: Inky)(unused x3: Inky)(unused x4: Inky, x5: Inky) = { println("fun") } - class Fun(y1: Inky, y2: Inky)(y3: Inky)(y4: Inky, y5: Inky) { + class Fun(unused y1: Inky, y2: Inky)(unused y3: Inky)(unused y4: Inky, y5: Inky) { println("Fun") } class Fun2 { println("Fun2") - def fun(z1: Inky, z2: Inky)(z3: Inky)(z4: Inky, z5: Inky) = { + def fun(unused z1: Inky, z2: Inky)(unused z3: Inky)(unused z4: Inky, z5: Inky) = { println("Fun2fun") } - def fun2[T](z1: Inky, z2: Inky)(z3: Inky)(z4: Inky, z5: Inky) = { + def fun2[T](unused z1: Inky, z2: Inky)(unused z3: Inky)(unused z4: Inky, z5: Inky) = { println("Fun2fun2") } } @@ -65,5 +65,5 @@ object Test { object Boo extends Phantom { type Inky <: this.Any - def boo: Inky = assume + unused def boo: Inky = assume } diff --git a/tests/run/phantom-methods-12.check b/tests/run/phantom-methods-12.check index 7a69fa94b7ea..d106cf661bd5 100644 --- a/tests/run/phantom-methods-12.check +++ b/tests/run/phantom-methods-12.check @@ -1,17 +1,7 @@ -x1 -x2 -x3 -x4 -x5 fun1 y1 y2 -y3 -y4 -y5 fun2 -z1 -z2 z3 z4 z5 diff --git a/tests/run/phantom-methods-12.scala b/tests/run/phantom-methods-12.scala index 84fb8aa905ff..11734748cb58 100644 --- a/tests/run/phantom-methods-12.scala +++ b/tests/run/phantom-methods-12.scala @@ -33,15 +33,15 @@ object Test { ) } - def fun1(x1: Inky, x2: Inky)(x3: Inky)(x4: Inky, x5: Inky) = { + def fun1(unused x1: Inky, x2: Inky)(unused x3: Inky)(unused x4: Inky, x5: Inky) = { println("fun1") } - def fun2(x1: Int, x2: Int)(x3: Inky)(x4: Inky, x5: Inky) = { + def fun2(x1: Int, x2: Int)(unused x3: Inky)(unused x4: Inky, x5: Inky) = { println("fun2") } - def fun3(x1: Inky, x2: Inky)(x3: Int)(x4: Int, x5: Int) = { + def fun3(unused x1: Inky, x2: Inky)(x3: Int)(x4: Int, x5: Int) = { println("fun3") } @@ -49,5 +49,5 @@ object Test { object Boo extends Phantom { type Inky <: this.Any - def boo: Inky = assume + unused def boo: Inky = assume } diff --git a/tests/run/phantom-methods-13.check b/tests/run/phantom-methods-13.check index 7a69fa94b7ea..14387a0f3130 100644 --- a/tests/run/phantom-methods-13.check +++ b/tests/run/phantom-methods-13.check @@ -1,17 +1,8 @@ -x1 -x2 x3 -x4 -x5 fun1 y1 y2 -y3 -y4 -y5 fun2 -z1 -z2 z3 z4 z5 diff --git a/tests/run/phantom-methods-13.scala b/tests/run/phantom-methods-13.scala index ef33c434acdb..7989dae6166f 100644 --- a/tests/run/phantom-methods-13.scala +++ b/tests/run/phantom-methods-13.scala @@ -33,15 +33,15 @@ object Test { ) } - def fun1[T](x1: Inky, x2: Inky)(x3: T)(x4: Inky, x5: Inky) = { + def fun1[T](unused x1: Inky, x2: Inky)(x3: T)(unused x4: Inky, x5: Inky) = { println("fun1") } - def fun2[T](x1: T, x2: T)(x3: Inky)(x4: Inky, x5: Inky) = { + def fun2[T](x1: T, x2: T)(unused x3: Inky)(unused x4: Inky, x5: Inky) = { println("fun2") } - def fun3[T](x1: Inky, x2: Inky)(x3: T)(x4: T, x5: T) = { + def fun3[T](unused x1: Inky, x2: Inky)(x3: T)(x4: T, x5: T) = { println("fun3") } @@ -49,5 +49,5 @@ object Test { object Boo extends Phantom { type Inky <: this.Any - def boo: Inky = assume + unused def boo: Inky = assume } diff --git a/tests/run/phantom-methods-14.scala b/tests/run/phantom-methods-14.scala index d149ddf1efed..0addf6556bd5 100644 --- a/tests/run/phantom-methods-14.scala +++ b/tests/run/phantom-methods-14.scala @@ -7,11 +7,11 @@ object Test { bar2(Foo.a)(null) } - def bar1(ev: Foo.A) = () - def bar2(ev: Foo.A)(implicit c: ClassTag[Int]) = implicitly[ClassTag[Int]] + def bar1(unused ev: Foo.A) = () + def bar2(unused ev: Foo.A)(implicit c: ClassTag[Int]) = implicitly[ClassTag[Int]] } object Foo extends Phantom { type A <: this.Any - def a: A = assume + unused def a: A = assume } diff --git a/tests/run/phantom-methods-2.scala b/tests/run/phantom-methods-2.scala index 7849f68d5303..690c233de19a 100644 --- a/tests/run/phantom-methods-2.scala +++ b/tests/run/phantom-methods-2.scala @@ -7,9 +7,9 @@ object Test { fun(phantomFun2(Boo.boo[Pinky])) } - def fun(top: Blinky): Unit = println("fun") + def fun(unused top: Blinky): Unit = println("fun") - def phantomFun2(p6: Blinky): Blinky = p6 + unused def phantomFun2(unused p6: Blinky): Blinky = p6 } @@ -17,5 +17,5 @@ object Boo extends Phantom { type Blinky <: Boo.Any type Inky <: Blinky type Pinky <: Inky - def boo[B <: Boo.Any]: B = assume + unused def boo[B <: Boo.Any]: B = assume } diff --git a/tests/run/phantom-methods-3.scala b/tests/run/phantom-methods-3.scala index cc43ed3b9acd..bf3711f33d78 100644 --- a/tests/run/phantom-methods-3.scala +++ b/tests/run/phantom-methods-3.scala @@ -7,9 +7,9 @@ object Test { fun(phantomFun3(boo[Pinky])) } - def fun(top: Blinky): Unit = println("fun") + def fun(unused top: Blinky): Unit = println("fun") - def phantomFun3[P <: Blinky](p7: P): Blinky = p7 + unused def phantomFun3[P <: Blinky](unused p7: P): Blinky = p7 } @@ -17,5 +17,5 @@ object Boo extends Phantom { type Blinky <: Boo.Any type Inky <: Blinky type Pinky <: Inky - def boo[B <: Boo.Any]: B = assume + unused def boo[B <: Boo.Any]: B = assume } diff --git a/tests/run/phantom-methods-4.scala b/tests/run/phantom-methods-4.scala index 50145d3a4641..ce223a2103d5 100644 --- a/tests/run/phantom-methods-4.scala +++ b/tests/run/phantom-methods-4.scala @@ -7,9 +7,9 @@ object Test { fun(phantomFun4(boo[Blinky])) } - def fun(top: Blinky): Unit = println("fun") + def fun(unused top: Blinky): Unit = println("fun") - def phantomFun4[G <: Blinky](p8: G): G = p8 + unused def phantomFun4[G <: Blinky](unused p8: G): G = p8 } @@ -17,5 +17,5 @@ object Boo extends Phantom { type Blinky <: Boo.Any type Inky <: Blinky type Pinky <: Inky - def boo[B <: Boo.Any]: B = assume + unused def boo[B <: Boo.Any]: B = assume } diff --git a/tests/run/phantom-methods-5.scala b/tests/run/phantom-methods-5.scala index 9dccf849f9ae..1deeab1dbb1b 100644 --- a/tests/run/phantom-methods-5.scala +++ b/tests/run/phantom-methods-5.scala @@ -7,7 +7,7 @@ object Test { pacFun1(boo[Pinky]) } - def pacFun1(blinky: Blinky) = { + def pacFun1(unused blinky: Blinky) = { println("customFun1") } @@ -17,5 +17,5 @@ object Boo extends Phantom { type Blinky <: Boo.Any type Inky <: Blinky type Pinky <: Inky - def boo[B <: Boo.Any]: B = assume + unused def boo[B <: Boo.Any]: B = assume } diff --git a/tests/run/phantom-methods-6.scala b/tests/run/phantom-methods-6.scala index 2de694a571c1..4d33232e2ca5 100644 --- a/tests/run/phantom-methods-6.scala +++ b/tests/run/phantom-methods-6.scala @@ -5,7 +5,7 @@ object Test { pacFun2(boo[Pinky]) } - def pacFun2(pinky: Pinky) = { + def pacFun2(unused pinky: Pinky) = { println("customPhantomsFun2") } @@ -15,5 +15,5 @@ object Boo extends Phantom { type Blinky <: Boo.Any type Inky <: Blinky type Pinky <: Inky - def boo[B <: Boo.Any]: B = assume + unused def boo[B <: Boo.Any]: B = assume } diff --git a/tests/run/phantom-methods-7.scala b/tests/run/phantom-methods-7.scala index 9e76501d99a3..f6ccea93ce5a 100644 --- a/tests/run/phantom-methods-7.scala +++ b/tests/run/phantom-methods-7.scala @@ -6,7 +6,7 @@ object Test { pacFun3(boo[Pinky]) } - def pacFun3(clyde: Clyde) = { + def pacFun3(unused clyde: Clyde) = { println("pacFun3") } } @@ -15,5 +15,5 @@ object Boo extends Phantom { type Inky <: Boo.Any type Pinky <: Inky type Clyde >: Pinky <: Inky - def boo[B <: Boo.Any]: B = assume + unused def boo[B <: Boo.Any]: B = assume } diff --git a/tests/run/phantom-methods-8.check b/tests/run/phantom-methods-8.check index 1046cb49e89d..1672323fe703 100644 --- a/tests/run/phantom-methods-8.check +++ b/tests/run/phantom-methods-8.check @@ -1,2 +1 @@ -inky pacFun4 diff --git a/tests/run/phantom-methods-8.scala b/tests/run/phantom-methods-8.scala index 21eeae6bfb5b..cfbadf5af99d 100644 --- a/tests/run/phantom-methods-8.scala +++ b/tests/run/phantom-methods-8.scala @@ -5,11 +5,11 @@ object Test { pacFun4(inky) } - def pacFun4(clyde: Inky) = { + def pacFun4(unused clyde: Inky) = { println("pacFun4") } - def inky: Inky = { + unused def inky: Inky = { println("inky") Boo.boo[Inky] } @@ -17,5 +17,5 @@ object Test { object Boo extends Phantom { type Inky <: Boo.Any - def boo[B <: Boo.Any]: B = assume + unused def boo[B <: Boo.Any]: B = assume } diff --git a/tests/run/phantom-methods-9.check b/tests/run/phantom-methods-9.check index 50cb66f41e35..5353be80d1af 100644 --- a/tests/run/phantom-methods-9.check +++ b/tests/run/phantom-methods-9.check @@ -1,3 +1,2 @@ fun -inky pacFun4 diff --git a/tests/run/phantom-methods-9.scala b/tests/run/phantom-methods-9.scala index c02d7cf9af03..dfd26dd1899d 100644 --- a/tests/run/phantom-methods-9.scala +++ b/tests/run/phantom-methods-9.scala @@ -5,11 +5,11 @@ object Test { fun1().pacFun4(inky) } - def pacFun4(clyde: Inky) = { + def pacFun4(unused clyde: Inky) = { println("pacFun4") } - def inky: Inky = { + unused def inky: Inky = { println("inky") boo[Inky] } @@ -22,5 +22,5 @@ object Test { object Boo extends Phantom { type Inky <: Boo.Any - def boo[B <: Boo.Any]: B = assume + unused def boo[B <: Boo.Any]: B = assume } diff --git a/tests/run/phantom-param-accessor.scala b/tests/run/phantom-param-accessor.scala index eab1bd13d17e..ce8a86e2d53b 100644 --- a/tests/run/phantom-param-accessor.scala +++ b/tests/run/phantom-param-accessor.scala @@ -2,13 +2,14 @@ import Boo._ object Test { def main(args: Array[String]): Unit = { - new Foo(a).aVal + foo(new Foo(a).aVal) } + def foo(unused a: A) = () } -class Foo(val aVal: A) +class Foo(unused val aVal: A) object Boo extends Phantom { type A = this.Nothing - def a = assume + unused def a: A = assume } diff --git a/tests/run/phantom-poly-1.scala b/tests/run/phantom-poly-1.scala index 822556f7a0ed..a5fc9b0c1c43 100644 --- a/tests/run/phantom-poly-1.scala +++ b/tests/run/phantom-poly-1.scala @@ -14,5 +14,5 @@ object Test { object Boo extends Phantom { type Casper <: this.Any - def boo[B <: this.Any]: B = assume + unused def boo[B <: this.Any]: B = assume } diff --git a/tests/run/phantom-poly-2.scala b/tests/run/phantom-poly-2.scala index 6a519573a8a0..2f660601e8dc 100644 --- a/tests/run/phantom-poly-2.scala +++ b/tests/run/phantom-poly-2.scala @@ -7,7 +7,7 @@ object Test { polyfun2(boo[Pinky]) } - def polyfun2[G <: Blinky](p: G): Unit = { + def polyfun2[G <: Blinky](unused p: G): Unit = { println("polyfun2") } } @@ -16,5 +16,5 @@ object Boo extends Phantom { type Blinky <: this.Any type Inky <: Blinky type Pinky <: Inky - def boo[B <: this.Any]: B = assume + unused def boo[B <: this.Any]: B = assume } diff --git a/tests/run/phantom-poly-3.scala b/tests/run/phantom-poly-3.scala index 65dbd137f9cf..2a1b8180c7cb 100644 --- a/tests/run/phantom-poly-3.scala +++ b/tests/run/phantom-poly-3.scala @@ -7,7 +7,7 @@ object Test { polyfun3(boo[Pinky]) } - def polyfun3[G <: BooAny, I <: G](q: I): Unit = { + def polyfun3[G <: BooAny, I <: G](unused q: I): Unit = { println("polyfun3") } } @@ -17,5 +17,5 @@ object Boo extends Phantom { type Blinky <: this.Any type Inky <: Blinky type Pinky <: Inky - def boo[B <: Blinky]: B = assume + unused def boo[B <: Blinky]: B = assume } diff --git a/tests/run/phantom-poly-4.scala b/tests/run/phantom-poly-4.scala index 697686fa8390..78fea153117d 100644 --- a/tests/run/phantom-poly-4.scala +++ b/tests/run/phantom-poly-4.scala @@ -7,7 +7,7 @@ object Test { polyfun4(boo[Pinky]) } - def polyfun4[P >: BooNothing](p: P): Unit = { + def polyfun4[P >: BooNothing](unused p: P): Unit = { println("polyfun4") } } @@ -17,5 +17,5 @@ object Boo extends Phantom { type Blinky <: this.Any type Inky <: Blinky type Pinky <: Inky - def boo[B <: Blinky]: B = assume + unused def boo[B <: Blinky]: B = assume } diff --git a/tests/run/phantom-self-1.scala b/tests/run/phantom-self-1.scala index 9c112ff57c96..827c4b3a5a76 100644 --- a/tests/run/phantom-self-1.scala +++ b/tests/run/phantom-self-1.scala @@ -1,14 +1,15 @@ object Test { def main(args: Array[String]): Unit = { - Boo.any - Boo.any2 + foo(Boo.any) + foo(Boo.any2) } + def foo(unused a: Boo.X) = () } object Boo extends Phantom with T trait T { self: Phantom => type X = self.Any - def any: X = self.assume - def any2: X = assume + unused def any: X = self.assume + unused def any2: X = assume } diff --git a/tests/run/phantom-val-2.check b/tests/run/phantom-val-2.check index 06b2967cef34..d00491fd7e5b 100644 --- a/tests/run/phantom-val-2.check +++ b/tests/run/phantom-val-2.check @@ -1,2 +1 @@ -foo 1 diff --git a/tests/run/phantom-val-2.scala b/tests/run/phantom-val-2.scala index 0fa3bb2ebf42..a67e0073239a 100644 --- a/tests/run/phantom-val-2.scala +++ b/tests/run/phantom-val-2.scala @@ -3,15 +3,17 @@ object Test { def main(args: Array[String]): Unit = { val f = new Foo println(1) - f.foo - f.foo + bar(f.foo) + bar(f.foo) assert(!f.getClass.getDeclaredFields.exists(_.getName.startsWith("foo")), "field foo not erased") } + + def bar(unused x: Boo.BooAny) = () } class Foo { import Boo._ - val foo = { + unused val foo = { println("foo") any } @@ -19,5 +21,5 @@ class Foo { object Boo extends Phantom { type BooAny = this.Any - def any: BooAny = assume + unused def any: BooAny = assume } diff --git a/tests/run/phantom-val.check b/tests/run/phantom-val.check index 06b2967cef34..d00491fd7e5b 100644 --- a/tests/run/phantom-val.check +++ b/tests/run/phantom-val.check @@ -1,2 +1 @@ -foo 1 diff --git a/tests/run/phantom-val.scala b/tests/run/phantom-val.scala index e514e8e312e4..f13bc97c76fb 100644 --- a/tests/run/phantom-val.scala +++ b/tests/run/phantom-val.scala @@ -3,18 +3,19 @@ object Test { def main(args: Array[String]): Unit = { println(1) - foo - foo - + bar(foo) + bar(foo) } - val foo = { + unused val foo = { println("foo") any } + + def bar(unused a: BooAny) = () } object Boo extends Phantom { type BooAny = this.Any - def any: BooAny = assume + unused def any: BooAny = assume } From 23b61fa9d9207bf6a41295ab8e70022ee25d8c9b Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Sun, 25 Feb 2018 16:02:11 +0100 Subject: [PATCH 2/2] Remove scala.Phantom --- compiler/src/dotty/tools/dotc/ast/tpd.scala | 1 - .../dotty/tools/dotc/core/Definitions.scala | 21 +-- .../src/dotty/tools/dotc/core/StdNames.scala | 1 - .../tools/dotc/core/SymDenotations.scala | 2 +- .../dotty/tools/dotc/core/TypeComparer.scala | 12 +- .../dotty/tools/dotc/core/TypeErasure.scala | 2 - .../src/dotty/tools/dotc/core/TypeOps.scala | 2 +- .../src/dotty/tools/dotc/core/Types.scala | 53 +------ .../dotc/transform/GenericSignatures.scala | 4 +- .../tools/dotc/transform/PhantomArgLift.scala | 69 --------- .../tools/dotc/typer/ErrorReporting.scala | 2 - .../src/dotty/tools/dotc/typer/Namer.scala | 2 +- .../dotty/tools/dotc/typer/TypeAssigner.scala | 48 ++---- .../src/dotty/tools/dotc/typer/Typer.scala | 8 +- .../dotty/tools/dotc/FromTastyTests.scala | 29 ---- docs/_includes/features.html | 2 +- docs/docs/reference/phantom-types.md | 137 ------------------ .../{unused-terms.md => unused-parameters.md} | 0 docs/sidebar.yml | 2 - library/src/dotty/runtime/ErasedPhantom.scala | 4 - library/src/scala/Phantom.scala | 12 -- tests/generic-java-signatures/phantom.check | 3 - tests/generic-java-signatures/phantom.scala | 21 --- .../phantom-overload-2.scala | 21 --- .../phantom-overload.scala | 28 ---- tests/neg/phantom-AndOr.scala | 18 --- tests/neg/phantom-Eq.scala | 38 ----- tests/neg/phantom-assume-1.scala | 4 - tests/neg/phantom-bottom.scala | 25 ---- tests/neg/phantom-classOf-1.scala | 10 -- tests/neg/phantom-classOf-2.scala | 10 -- tests/neg/phantom-evidence.scala | 27 ---- tests/neg/phantom-expr.scala | 49 ------- tests/neg/phantom-fun-app.scala | 24 --- tests/neg/phantom-in-value-class.scala | 11 -- tests/neg/phantom-instanceOf-1.scala | 11 -- tests/neg/phantom-instanceOf-2.scala | 14 -- tests/neg/phantom-multiversal-AndOr.scala | 21 --- ...ntom-multiversal-type-param-bounds-1.scala | 18 --- ...ntom-multiversal-type-param-bounds-2.scala | 22 --- tests/neg/phantom-multiversal.scala | 35 ----- tests/neg/phantom-trait-1.scala | 4 - tests/neg/phantom-trait-2.scala | 5 - tests/neg/phantom-trait-3.scala | 6 - tests/neg/phantom-trait-4.scala | 23 --- tests/neg/phantom-type-param-bounds-1.scala | 9 -- tests/neg/phantom-type-param-bounds-2.scala | 13 -- tests/neg/phantom-var-2.scala | 9 -- tests/neg/phantom-var.scala | 9 -- tests/neg/reference-phantom-type-1.scala | 24 --- tests/neg/reference-phantom-type-2.scala | 21 --- tests/pos/phantom-Eq.scala | 16 +- tests/pos/phantom-Eq2/Phantom-Eq_1.scala | 17 ++- tests/pos/phantom-Evidence.scala | 6 +- tests/pos/reference/phantom-types.scala | 29 ---- tests/run/phantom-1.check | 1 - tests/run/phantom-1.scala | 16 -- tests/run/phantom-2.check | 1 - tests/run/phantom-2.scala | 16 -- tests/run/phantom-3.check | 3 - tests/run/phantom-3.scala | 21 --- tests/run/phantom-4.check | 3 - tests/run/phantom-4.scala | 22 --- tests/run/phantom-5.check | 3 - tests/run/phantom-5.scala | 22 --- tests/run/phantom-OnHList.scala | 8 +- tests/run/phantom-assume-1.check | 0 tests/run/phantom-assume-1.scala | 19 --- tests/run/phantom-decls-1.check | 4 - tests/run/phantom-decls-1.scala | 24 --- tests/run/phantom-decls-2.check | 6 - tests/run/phantom-decls-2.scala | 26 ---- tests/run/phantom-decls-3.check | 4 - tests/run/phantom-decls-3.scala | 31 ---- tests/run/phantom-decls-4.check | 3 - tests/run/phantom-decls-4.scala | 20 --- tests/run/phantom-decls-5.check | 2 - tests/run/phantom-decls-5.scala | 19 --- tests/run/phantom-erased-methods.check | 0 tests/run/phantom-erased-methods.scala | 31 ---- tests/run/phantom-hk-1.check | 3 - tests/run/phantom-hk-1.scala | 27 ---- tests/run/phantom-hk-2.check | 3 - tests/run/phantom-hk-2.scala | 24 --- tests/run/phantom-in-value-class.scala | 24 --- tests/run/phantom-methods-1.check | 0 tests/run/phantom-methods-1.scala | 17 --- tests/run/phantom-methods-10.check | 2 - tests/run/phantom-methods-10.scala | 26 ---- tests/run/phantom-methods-11.check | 6 - tests/run/phantom-methods-11.scala | 69 --------- tests/run/phantom-methods-12.check | 8 - tests/run/phantom-methods-12.scala | 53 ------- tests/run/phantom-methods-13.check | 9 -- tests/run/phantom-methods-13.scala | 53 ------- tests/run/phantom-methods-14.check | 0 tests/run/phantom-methods-14.scala | 17 --- tests/run/phantom-methods-2.check | 3 - tests/run/phantom-methods-2.scala | 21 --- tests/run/phantom-methods-3.check | 3 - tests/run/phantom-methods-3.scala | 21 --- tests/run/phantom-methods-4.check | 3 - tests/run/phantom-methods-4.scala | 21 --- tests/run/phantom-methods-5.check | 3 - tests/run/phantom-methods-5.scala | 21 --- tests/run/phantom-methods-6.check | 1 - tests/run/phantom-methods-6.scala | 19 --- tests/run/phantom-methods-7.check | 2 - tests/run/phantom-methods-7.scala | 19 --- tests/run/phantom-methods-8.check | 1 - tests/run/phantom-methods-8.scala | 21 --- tests/run/phantom-methods-9.check | 2 - tests/run/phantom-methods-9.scala | 26 ---- tests/run/phantom-param-accessor.scala | 15 -- tests/run/phantom-poly-1.check | 2 - tests/run/phantom-poly-1.scala | 18 --- tests/run/phantom-poly-2.check | 3 - tests/run/phantom-poly-2.scala | 20 --- tests/run/phantom-poly-3.check | 3 - tests/run/phantom-poly-3.scala | 21 --- tests/run/phantom-poly-4.check | 3 - tests/run/phantom-poly-4.scala | 21 --- tests/run/phantom-self-1.check | 0 tests/run/phantom-self-1.scala | 15 -- tests/run/phantom-val-2.check | 1 - tests/run/phantom-val-2.scala | 25 ---- tests/run/phantom-val.check | 1 - tests/run/phantom-val.scala | 21 --- 128 files changed, 54 insertions(+), 1962 deletions(-) delete mode 100644 compiler/src/dotty/tools/dotc/transform/PhantomArgLift.scala delete mode 100644 docs/docs/reference/phantom-types.md rename docs/docs/reference/{unused-terms.md => unused-parameters.md} (100%) delete mode 100644 library/src/dotty/runtime/ErasedPhantom.scala delete mode 100644 library/src/scala/Phantom.scala delete mode 100644 tests/generic-java-signatures/phantom.check delete mode 100644 tests/generic-java-signatures/phantom.scala delete mode 100644 tests/neg-custom-args/allow-double-bindings/phantom-overload-2.scala delete mode 100644 tests/neg-custom-args/allow-double-bindings/phantom-overload.scala delete mode 100644 tests/neg/phantom-AndOr.scala delete mode 100644 tests/neg/phantom-Eq.scala delete mode 100644 tests/neg/phantom-assume-1.scala delete mode 100644 tests/neg/phantom-bottom.scala delete mode 100644 tests/neg/phantom-classOf-1.scala delete mode 100644 tests/neg/phantom-classOf-2.scala delete mode 100644 tests/neg/phantom-evidence.scala delete mode 100644 tests/neg/phantom-expr.scala delete mode 100644 tests/neg/phantom-fun-app.scala delete mode 100644 tests/neg/phantom-in-value-class.scala delete mode 100644 tests/neg/phantom-instanceOf-1.scala delete mode 100644 tests/neg/phantom-instanceOf-2.scala delete mode 100644 tests/neg/phantom-multiversal-AndOr.scala delete mode 100644 tests/neg/phantom-multiversal-type-param-bounds-1.scala delete mode 100644 tests/neg/phantom-multiversal-type-param-bounds-2.scala delete mode 100644 tests/neg/phantom-multiversal.scala delete mode 100644 tests/neg/phantom-trait-1.scala delete mode 100644 tests/neg/phantom-trait-2.scala delete mode 100644 tests/neg/phantom-trait-3.scala delete mode 100644 tests/neg/phantom-trait-4.scala delete mode 100644 tests/neg/phantom-type-param-bounds-1.scala delete mode 100644 tests/neg/phantom-type-param-bounds-2.scala delete mode 100644 tests/neg/phantom-var-2.scala delete mode 100644 tests/neg/phantom-var.scala delete mode 100644 tests/neg/reference-phantom-type-1.scala delete mode 100644 tests/neg/reference-phantom-type-2.scala delete mode 100644 tests/pos/reference/phantom-types.scala delete mode 100644 tests/run/phantom-1.check delete mode 100644 tests/run/phantom-1.scala delete mode 100644 tests/run/phantom-2.check delete mode 100644 tests/run/phantom-2.scala delete mode 100644 tests/run/phantom-3.check delete mode 100644 tests/run/phantom-3.scala delete mode 100644 tests/run/phantom-4.check delete mode 100644 tests/run/phantom-4.scala delete mode 100644 tests/run/phantom-5.check delete mode 100644 tests/run/phantom-5.scala delete mode 100644 tests/run/phantom-assume-1.check delete mode 100644 tests/run/phantom-assume-1.scala delete mode 100644 tests/run/phantom-decls-1.check delete mode 100644 tests/run/phantom-decls-1.scala delete mode 100644 tests/run/phantom-decls-2.check delete mode 100644 tests/run/phantom-decls-2.scala delete mode 100644 tests/run/phantom-decls-3.check delete mode 100644 tests/run/phantom-decls-3.scala delete mode 100644 tests/run/phantom-decls-4.check delete mode 100644 tests/run/phantom-decls-4.scala delete mode 100644 tests/run/phantom-decls-5.check delete mode 100644 tests/run/phantom-decls-5.scala delete mode 100644 tests/run/phantom-erased-methods.check delete mode 100644 tests/run/phantom-erased-methods.scala delete mode 100644 tests/run/phantom-hk-1.check delete mode 100644 tests/run/phantom-hk-1.scala delete mode 100644 tests/run/phantom-hk-2.check delete mode 100644 tests/run/phantom-hk-2.scala delete mode 100644 tests/run/phantom-in-value-class.scala delete mode 100644 tests/run/phantom-methods-1.check delete mode 100644 tests/run/phantom-methods-1.scala delete mode 100644 tests/run/phantom-methods-10.check delete mode 100644 tests/run/phantom-methods-10.scala delete mode 100644 tests/run/phantom-methods-11.check delete mode 100644 tests/run/phantom-methods-11.scala delete mode 100644 tests/run/phantom-methods-12.check delete mode 100644 tests/run/phantom-methods-12.scala delete mode 100644 tests/run/phantom-methods-13.check delete mode 100644 tests/run/phantom-methods-13.scala delete mode 100644 tests/run/phantom-methods-14.check delete mode 100644 tests/run/phantom-methods-14.scala delete mode 100644 tests/run/phantom-methods-2.check delete mode 100644 tests/run/phantom-methods-2.scala delete mode 100644 tests/run/phantom-methods-3.check delete mode 100644 tests/run/phantom-methods-3.scala delete mode 100644 tests/run/phantom-methods-4.check delete mode 100644 tests/run/phantom-methods-4.scala delete mode 100644 tests/run/phantom-methods-5.check delete mode 100644 tests/run/phantom-methods-5.scala delete mode 100644 tests/run/phantom-methods-6.check delete mode 100644 tests/run/phantom-methods-6.scala delete mode 100644 tests/run/phantom-methods-7.check delete mode 100644 tests/run/phantom-methods-7.scala delete mode 100644 tests/run/phantom-methods-8.check delete mode 100644 tests/run/phantom-methods-8.scala delete mode 100644 tests/run/phantom-methods-9.check delete mode 100644 tests/run/phantom-methods-9.scala delete mode 100644 tests/run/phantom-param-accessor.scala delete mode 100644 tests/run/phantom-poly-1.check delete mode 100644 tests/run/phantom-poly-1.scala delete mode 100644 tests/run/phantom-poly-2.check delete mode 100644 tests/run/phantom-poly-2.scala delete mode 100644 tests/run/phantom-poly-3.check delete mode 100644 tests/run/phantom-poly-3.scala delete mode 100644 tests/run/phantom-poly-4.check delete mode 100644 tests/run/phantom-poly-4.scala delete mode 100644 tests/run/phantom-self-1.check delete mode 100644 tests/run/phantom-self-1.scala delete mode 100644 tests/run/phantom-val-2.check delete mode 100644 tests/run/phantom-val-2.scala delete mode 100644 tests/run/phantom-val.check delete mode 100644 tests/run/phantom-val.scala diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index a16dc7e7cc4e..d2061204c83a 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -442,7 +442,6 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { else if (tpw isRef defn.DoubleClass) Literal(Constant(0d)) else if (tpw isRef defn.ByteClass) Literal(Constant(0.toByte)) else if (tpw isRef defn.ShortClass) Literal(Constant(0.toShort)) - else if (tpw.isPhantom) Literal(Constant(null)).withType(tpw) else Literal(Constant(null)).select(defn.Any_asInstanceOf).appliedToType(tpe) } diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 09712b629c3a..f083075607e1 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -1161,8 +1161,7 @@ class Definitions { NullClass, NothingClass, SingletonClass, - EqualsPatternClass, - PhantomClass) + EqualsPatternClass) lazy val syntheticCoreClasses = syntheticScalaClasses ++ List( EmptyPackageVal, @@ -1191,22 +1190,4 @@ class Definitions { } } - // ----- Phantoms --------------------------------------------------------- - - lazy val PhantomClass: ClassSymbol = { - val cls = completeClass(enterCompleteClassSymbol(ScalaPackageClass, tpnme.Phantom, NoInitsTrait, List(AnyType))) - - val any = enterCompleteClassSymbol(cls, tpnme.Any, Protected | Final | NoInitsTrait, Nil) - val nothing = enterCompleteClassSymbol(cls, tpnme.Nothing, Protected | Final | NoInitsTrait, List(any.typeRef)) - enterMethod(cls, nme.assume_, ExprType(nothing.typeRef), Protected | Final | Method | Unused) - - cls - } - lazy val Phantom_AnyClass = PhantomClass.unforcedDecls.find(_.name eq tpnme.Any).asClass - lazy val Phantom_NothingClass = PhantomClass.unforcedDecls.find(_.name eq tpnme.Nothing).asClass - - /** If the symbol is of the class scala.Phantom.Any or scala.Phantom.Nothing */ - def isPhantomTerminalClass(sym: Symbol) = (sym eq Phantom_AnyClass) || (sym eq Phantom_NothingClass) - - lazy val ErasedPhantomType: TypeRef = ctx.requiredClassRef("dotty.runtime.ErasedPhantom") } diff --git a/compiler/src/dotty/tools/dotc/core/StdNames.scala b/compiler/src/dotty/tools/dotc/core/StdNames.scala index dd63cd5cf087..c0c90b45b487 100644 --- a/compiler/src/dotty/tools/dotc/core/StdNames.scala +++ b/compiler/src/dotty/tools/dotc/core/StdNames.scala @@ -241,7 +241,6 @@ object StdNames { final val SourceFileATTR: N = "SourceFile" final val SyntheticATTR: N = "Synthetic" - final val Phantom: N = "Phantom" // ----- Term names ----------------------------------------- diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 757c6490e275..b1d300c922e9 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -667,7 +667,7 @@ object SymDenotations { /** Is this symbol a class references to which that are supertypes of null? */ final def isNullableClass(implicit ctx: Context): Boolean = - isClass && !isValueClass && !(this is ModuleClass) && symbol != defn.NothingClass && !defn.isPhantomTerminalClass(symbol) + isClass && !isValueClass && !(this is ModuleClass) && symbol != defn.NothingClass /** Is this definition accessible as a member of tree with type `pre`? * @param pre The type of the tree from which the selection is made diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 24802412a598..3e2fc62c7a7f 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -50,7 +50,6 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { private[this] var myAnyClass: ClassSymbol = null private[this] var myNothingClass: ClassSymbol = null private[this] var myNullClass: ClassSymbol = null - private[this] var myPhantomNothingClass: ClassSymbol = null private[this] var myObjectClass: ClassSymbol = null private[this] var myAnyType: TypeRef = null private[this] var myNothingType: TypeRef = null @@ -67,10 +66,6 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { if (myNullClass == null) myNullClass = defn.NullClass myNullClass } - def PhantomNothingClass = { - if (myPhantomNothingClass == null) myPhantomNothingClass = defn.Phantom_NothingClass - myPhantomNothingClass - } def ObjectClass = { if (myObjectClass == null) myObjectClass = defn.ObjectClass myObjectClass @@ -287,7 +282,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { if (recur(info1.alias, tp2)) return true if (tp1.prefix.isStable) return false case _ => - if (tp1 eq NothingType) return tp1 == tp2.bottomType + if (tp1 eq NothingType) return true } thirdTry case tp1: TypeParamRef => @@ -586,9 +581,8 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling { case _ => false } val sym1 = tp1.symbol - (sym1 eq NothingClass) && tp2.isValueTypeOrLambda && !tp2.isPhantom || - (sym1 eq NullClass) && isNullable(tp2) || - (sym1 eq PhantomNothingClass) && tp1.topType == tp2.topType + (sym1 eq NothingClass) && tp2.isValueTypeOrLambda || + (sym1 eq NullClass) && isNullable(tp2) } case tp1 @ AppliedType(tycon1, args1) => compareAppliedType1(tp1, tycon1, args1) diff --git a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala index 8685ce78a1a5..b0971f601fa1 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeErasure.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeErasure.scala @@ -380,8 +380,6 @@ class TypeErasure(isJava: Boolean, semiEraseVCs: Boolean, isConstructor: Boolean else if (semiEraseVCs && isDerivedValueClass(sym)) eraseDerivedValueClassRef(tp) else if (sym == defn.ArrayClass) apply(tp.appliedTo(TypeBounds.empty)) // i966 shows that we can hit a raw Array type. else if (defn.isSyntheticFunctionClass(sym)) defn.erasedFunctionType(sym) - else if (defn.isPhantomTerminalClass(sym)) defn.ErasedPhantomType - else if (sym eq defn.PhantomClass) defn.ObjectType // To erase the definitions of Phantom.{assume, Any, Nothing} else eraseNormalClassRef(tp) case tp: AppliedType => if (tp.tycon.isRef(defn.ArrayClass)) eraseArray(tp) diff --git a/compiler/src/dotty/tools/dotc/core/TypeOps.scala b/compiler/src/dotty/tools/dotc/core/TypeOps.scala index 4fa3dcea4bf3..754186c8376e 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeOps.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeOps.scala @@ -42,7 +42,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object. case pre: SuperType => toPrefix(pre.thistpe, cls, thiscls) case _ => if (thiscls.derivesFrom(cls) && pre.baseType(thiscls).exists) - if (variance <= 0 && !isLegalPrefix(pre)) range(pre.bottomType, pre) + if (variance <= 0 && !isLegalPrefix(pre)) range(defn.NothingType, pre) else pre else if ((pre.termSymbol is Package) && !(thiscls is Package)) toPrefix(pre.select(nme.PACKAGE), cls, thiscls) diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 8a2bece2baf8..d62752721291 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -193,59 +193,18 @@ object Types { } } - /** Returns true if the type is a phantom type - * - true if XYZ extends scala.Phantom and this type is upper bounded XYZ.Any - * - false otherwise - */ - final def isPhantom(implicit ctx: Context): Boolean = phantomLatticeType.exists - - /** Returns the top type of the lattice - * - XYX.Any if XYZ extends scala.Phantom and this type is upper bounded XYZ.Any - * - scala.Any otherwise - */ - final def topType(implicit ctx: Context): Type = { - val lattice = phantomLatticeType - if (lattice.exists) lattice.select(tpnme.Any) - else defn.AnyType - } - - /** Returns the bottom type of the lattice - * - XYZ.Nothing if XYZ extends scala.Phantom and this type is upper bounded XYZ.Any - * - scala.Nothing otherwise - */ - final def bottomType(implicit ctx: Context): Type = { - val lattice = phantomLatticeType - if (lattice.exists) lattice.select(tpnme.Nothing) - else defn.NothingType - } - /** Is this type exactly Nothing (no vars, aliases, refinements etc allowed)? */ def isBottomType(implicit ctx: Context): Boolean = this match { - case tp: TypeRef => - val sym = tp.symbol - (sym eq defn.NothingClass) || (sym eq defn.Phantom_NothingClass) + case tp: TypeRef => tp.symbol eq defn.NothingClass case _ => false } /** Is this type exactly Any (no vars, aliases, refinements etc allowed)? */ def isTopType(implicit ctx: Context): Boolean = this match { - case tp: TypeRef => - val sym = tp.symbol - (sym eq defn.AnyClass) || (sym eq defn.Phantom_AnyClass) + case tp: TypeRef => tp.symbol eq defn.AnyClass case _ => false } - /** Returns the type of the phantom lattice (i.e. the prefix of the phantom type) - * - XYZ if XYZ extends scala.Phantom and this type is upper bounded XYZ.Any - * - NoType otherwise - */ - private final def phantomLatticeType(implicit ctx: Context): Type = widen match { - case tp: ClassInfo if defn.isPhantomTerminalClass(tp.classSymbol) => tp.prefix - case tp: TypeProxy => tp.underlying.phantomLatticeType - case tp: AndOrType => tp.tp1.phantomLatticeType - case _ => NoType - } - /** Is this type a (possibly aliased) singleton type? */ def isSingleton(implicit ctx: Context) = dealias.isInstanceOf[SingletonType] @@ -2860,7 +2819,7 @@ object Types { val dropDependencies = new ApproximatingTypeMap { def apply(tp: Type) = tp match { case tp @ TermParamRef(thisLambdaType, _) => - range(tp.bottomType, atVariance(1)(apply(tp.underlying))) + range(defn.NothingType, atVariance(1)(apply(tp.underlying))) case _ => mapOver(tp) } } @@ -4177,7 +4136,7 @@ object Types { case Range(infoLo: TypeBounds, infoHi: TypeBounds) => assert(variance == 0) if (!infoLo.isAlias && !infoHi.isAlias) propagate(infoLo, infoHi) - else range(tp.bottomType, tp.parent) + else range(defn.NothingType, tp.parent) case Range(infoLo, infoHi) => propagate(infoLo, infoHi) case _ => @@ -4209,7 +4168,7 @@ object Types { else tp.derivedTypeBounds(lo, hi) override protected def derivedSuperType(tp: SuperType, thistp: Type, supertp: Type) = - if (isRange(thistp) || isRange(supertp)) range(thistp.bottomType, thistp.topType) + if (isRange(thistp) || isRange(supertp)) range(defn.NothingType, defn.AnyType) else tp.derivedSuperType(thistp, supertp) override protected def derivedAppliedType(tp: AppliedType, tycon: Type, args: List[Type]): Type = @@ -4246,7 +4205,7 @@ object Types { if (distributeArgs(args, tp.typeParams)) range(tp.derivedAppliedType(tycon, loBuf.toList), tp.derivedAppliedType(tycon, hiBuf.toList)) - else range(tp.bottomType, tp.topType) + else range(defn.NothingType, defn.AnyType) // TODO: can we give a better bound than `topType`? } } diff --git a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala index eea3c42aa9a3..86c9ed7a767e 100644 --- a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala +++ b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala @@ -212,8 +212,6 @@ object GenericSignatures { else jsig(unboxedSeen, toplevel, primitiveOK) } - else if (tp.isPhantom) - jsig(defn.ErasedPhantomType) else if (sym.isClass) classSig else @@ -242,7 +240,7 @@ object GenericSignatures { // unused method parameters do not make it to the bytecode. def effectiveParamInfoss(t: Type)(implicit ctx: Context): List[List[Type]] = t match { case t: MethodType if t.isUnusedMethod => effectiveParamInfoss(t.resType) - case t: MethodType => t.paramInfos.filterNot(_.isPhantom) :: effectiveParamInfoss(t.resType) + case t: MethodType => t.paramInfos :: effectiveParamInfoss(t.resType) case _ => Nil } val params = effectiveParamInfoss(mtpe).flatten diff --git a/compiler/src/dotty/tools/dotc/transform/PhantomArgLift.scala b/compiler/src/dotty/tools/dotc/transform/PhantomArgLift.scala deleted file mode 100644 index 3c4b439f7060..000000000000 --- a/compiler/src/dotty/tools/dotc/transform/PhantomArgLift.scala +++ /dev/null @@ -1,69 +0,0 @@ -package dotty.tools.dotc.transform - -import dotty.tools.dotc.ast.tpd -import dotty.tools.dotc.core.Contexts._ -import dotty.tools.dotc.core.NameKinds._ -import dotty.tools.dotc.core.Types._ -import dotty.tools.dotc.transform.MegaPhase.MiniPhase -import dotty.tools.dotc.typer.LiftImpure - -import scala.collection.mutable.ListBuffer - -/** This phase extracts the arguments of phantom type before the application to avoid losing any - * effects in the argument tree. This trivializes the removal of parameter in the Erasure phase. - * - * `f(x1,...)(y1,...)...(...)` with at least one phantom argument - * - * --> - * - * `val ev$f = f` // if `f` is some expression that needs evaluation - * `val ev$x1 = x1` - * ... - * `val ev$y1 = y1` - * ... - * `ev$f(ev$x1,...)(ev$y1,...)...(...)` - * - */ -class PhantomArgLift extends MiniPhase { - import tpd._ - - override def phaseName: String = "phantomArgLift" - - /** Check what the phase achieves, to be called at any point after it is finished. */ - override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit = tree match { - case tree: Apply => - tree.args.foreach { arg => - assert(!arg.tpe.isPhantom || isPureExpr(arg)) - } - case _ => - } - - /* Tree transform */ - - override def transformApply(tree: Apply)(implicit ctx: Context): Tree = tree.tpe.widen match { - case _: MethodType => tree // Do the transformation higher in the tree if needed - case _ => - if (!hasImpurePhantomArgs(tree)) tree - else { - val buffer = ListBuffer.empty[Tree] - val app = LiftImpure.liftApp(buffer, tree) - if (buffer.isEmpty) app - else Block(buffer.result(), app) - } - } - - /* private methods */ - - /** Returns true if at least on of the arguments is an impure phantom. - * Inner applies are also checked in case of multiple parameter list. - */ - private def hasImpurePhantomArgs(tree: Apply)(implicit ctx: Context): Boolean = { - tree.args.exists(arg => arg.tpe.isPhantom && !isPureExpr(arg)) || { - tree.fun match { - case fun: Apply => hasImpurePhantomArgs(fun) - case _ => false - } - } - } - -} diff --git a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala index 4b865476d6e2..adce2ad9a537 100644 --- a/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala +++ b/compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala @@ -121,8 +121,6 @@ object ErrorReporting { val expected1 = dropJavaMethod(expected) if ((found1 eq found) != (expected eq expected1) && (found1 <:< expected1)) "\n(Note that Scala's and Java's representation of this type differs)" - else if (found.topType != expected.topType) - "\n(Note that the types are in different universes, see Phantom types)" else if (ctx.settings.explainTypes.value) "\n" + ctx.typerState.show + "\n" + TypeComparer.explained((found <:< expected)(_)) else diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 390ceb0ab0ca..14b9cbcc556c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -1120,7 +1120,7 @@ class Namer { typer: Typer => val deskolemize = new ApproximatingTypeMap { def apply(tp: Type) = /*trace(i"deskolemize($tp) at $variance", show = true)*/ { tp match { - case tp: SkolemType => range(tp.bottomType, atVariance(1)(apply(tp.info))) + case tp: SkolemType => range(defn.NothingType, atVariance(1)(apply(tp.info))) case _ => mapOver(tp) } } diff --git a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala index 3ba549c9d301..2787c133fb29 100644 --- a/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -95,7 +95,7 @@ trait TypeAssigner { if toAvoid(tp.symbol) || partsToAvoid(mutable.Set.empty, tp.info).nonEmpty => tp.info.widenExpr.dealias match { case info: SingletonType => apply(info) - case info => range(tp.info.bottomType, apply(info)) + case info => range(defn.NothingType, apply(info)) } case tp: TypeRef if toAvoid(tp.symbol) => tp.info match { @@ -104,14 +104,14 @@ trait TypeAssigner { case TypeBounds(lo, hi) => range(atVariance(-variance)(apply(lo)), apply(hi)) case info: ClassInfo => - range(tp.bottomType, apply(classBound(info))) + range(defn.NothingType, apply(classBound(info))) case _ => - range(tp.bottomType, tp.topType) // should happen only in error cases + range(defn.NothingType, defn.AnyType) // should happen only in error cases } case tp: ThisType if toAvoid(tp.cls) => - range(tp.bottomType, apply(classBound(tp.cls.classInfo))) + range(defn.NothingType, apply(classBound(tp.cls.classInfo))) case tp: SkolemType if partsToAvoid(mutable.Set.empty, tp.info).nonEmpty => - range(tp.info.bottomType, apply(tp.info)) + range(defn.NothingType, apply(tp.info)) case tp: TypeVar if ctx.typerState.constraint.contains(tp) => val lo = ctx.typeComparer.instanceType( tp.origin, fromBelow = variance > 0 || variance == 0 && tp.hasLowerBound) @@ -139,7 +139,7 @@ trait TypeAssigner { else if (upper(pre).member(tp.name).exists) super.derivedSelect(tp, pre) else - range(tp.bottomType, tp.topType) + range(defn.NothingType, defn.AnyType) } } @@ -450,7 +450,7 @@ trait TypeAssigner { tree.withType(avoidingType(expansion, bindings)) def assignType(tree: untpd.If, thenp: Tree, elsep: Tree)(implicit ctx: Context) = - tree.withType(lubInSameUniverse(thenp :: elsep :: Nil, "branches of an if/else")) + tree.withType(thenp.tpe | elsep.tpe) def assignType(tree: untpd.Closure, meth: Tree, target: Tree)(implicit ctx: Context) = tree.withType( @@ -460,18 +460,15 @@ trait TypeAssigner { def assignType(tree: untpd.CaseDef, body: Tree)(implicit ctx: Context) = tree.withType(body.tpe) - def assignType(tree: untpd.Match, cases: List[CaseDef])(implicit ctx: Context) = { - if (tree.selector.typeOpt.isPhantom) - ctx.error("cannot pattern match on values of a phantom type", tree.selector.pos) - tree.withType(lubInSameUniverse(cases, "branches of a match")) - } + def assignType(tree: untpd.Match, cases: List[CaseDef])(implicit ctx: Context) = + tree.withType(ctx.typeComparer.lub(cases.tpes)) def assignType(tree: untpd.Return)(implicit ctx: Context) = tree.withType(defn.NothingType) def assignType(tree: untpd.Try, expr: Tree, cases: List[CaseDef])(implicit ctx: Context) = if (cases.isEmpty) tree.withType(expr.tpe) - else tree.withType(lubInSameUniverse(expr :: cases, "branches of a try")) + else tree.withType(ctx.typeComparer.lub(expr.tpe :: cases.tpes)) def assignType(tree: untpd.SeqLiteral, elems: List[Tree], elemtpt: Tree)(implicit ctx: Context) = { val ownType = tree match { @@ -485,10 +482,10 @@ trait TypeAssigner { tree.withType(ref.tpe) def assignType(tree: untpd.AndTypeTree, left: Tree, right: Tree)(implicit ctx: Context) = - tree.withType(inSameUniverse(AndType(_, _), left.tpe, right, "an `&`")) + tree.withType(AndType(left.tpe, right.tpe)) def assignType(tree: untpd.OrTypeTree, left: Tree, right: Tree)(implicit ctx: Context) = - tree.withType(inSameUniverse(OrType(_, _), left.tpe, right, "an `|`")) + tree.withType(OrType(left.tpe, right.tpe)) /** Assign type of RefinedType. * Refinements are typed as if they were members of refinement class `refineCls`. @@ -521,9 +518,7 @@ trait TypeAssigner { tree.withType(ExprType(result.tpe)) def assignType(tree: untpd.TypeBoundsTree, lo: Tree, hi: Tree)(implicit ctx: Context) = - tree.withType( - if (lo eq hi) TypeAlias(lo.tpe) - else inSameUniverse(TypeBounds(_, _), lo.tpe, hi, "type bounds")) + tree.withType(if (lo eq hi) TypeAlias(lo.tpe) else TypeBounds(lo.tpe, hi.tpe)) def assignType(tree: untpd.Bind, sym: Symbol)(implicit ctx: Context) = tree.withType(NamedType(NoPrefix, sym)) @@ -554,23 +549,6 @@ trait TypeAssigner { def assignType(tree: untpd.PackageDef, pid: Tree)(implicit ctx: Context) = tree.withType(pid.symbol.termRef) - /** Ensure that `tree2`'s type is in the same universe as `tree1`. If that's the case, return - * `op` applied to both types. - * If not, issue an error and return `tree1`'s type. - */ - private def inSameUniverse(op: (Type, Type) => Type, tp1: Type, tree2: Tree, relationship: => String)(implicit ctx: Context): Type = - if (tp1.topType == tree2.tpe.topType) - op(tp1, tree2.tpe) - else { - ctx.error(ex"$tp1 and ${tree2.tpe} are in different universes. They cannot be combined in $relationship", tree2.pos) - tp1 - } - - private def lubInSameUniverse(trees: List[Tree], relationship: => String)(implicit ctx: Context): Type = - trees match { - case first :: rest => (first.tpe /: rest)(inSameUniverse(_ | _, _, _, relationship)) - case Nil => defn.NothingType - } } object TypeAssigner extends TypeAssigner diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 5bc0234989ca..04237b2bc1e9 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1268,8 +1268,8 @@ class Typer extends Namer val lo1 = typed(lo) val hi1 = typed(hi) - val lo2 = if (lo1.isEmpty) typed(untpd.TypeTree(hi1.typeOpt.bottomType)) else lo1 - val hi2 = if (hi1.isEmpty) typed(untpd.TypeTree(lo1.typeOpt.topType)) else hi1 + val lo2 = if (lo1.isEmpty) typed(untpd.TypeTree(defn.NothingType)) else lo1 + val hi2 = if (hi1.isEmpty) typed(untpd.TypeTree(defn.AnyType)) else hi1 val tree1 = assignType(cpy.TypeBoundsTree(tree)(lo2, hi2), lo2, hi2) if (ctx.mode.is(Mode.Pattern)) { @@ -1515,10 +1515,6 @@ class Typer extends Namer cls, isRequired, cdef.pos) } - // Check that phantom lattices are defined in a static object - if (cls.classParents.exists(_.typeSymbol eq defn.PhantomClass) && !cls.isStaticOwner) - ctx.error("only static objects can extend scala.Phantom", cdef.pos) - // check value class constraints checkDerivedValueClass(cls, body1) diff --git a/compiler/test/dotty/tools/dotc/FromTastyTests.scala b/compiler/test/dotty/tools/dotc/FromTastyTests.scala index fe9f2427fcb3..e48fa73198eb 100644 --- a/compiler/test/dotty/tools/dotc/FromTastyTests.scala +++ b/compiler/test/dotty/tools/dotc/FromTastyTests.scala @@ -83,9 +83,6 @@ class FromTastyTests extends ParallelTesting { // Infinite compilation "t3612.scala", - - "phantom-Eq.scala", - "phantom-Evidence.scala", ) ) step1.checkCompile() // Compile all files to generate the class files with tasty @@ -147,32 +144,6 @@ class FromTastyTests extends ParallelTesting { "unused-21.scala", "unused-23.scala", "unused-value-class.scala", - "phantom-methods-12.scala", - "phantom-methods-8.scala", - "phantom-methods-2.scala", - "phantom-methods-9.scala", - "phantom-methods-13.scala", - "phantom-methods-14.scala", - "phantom-decls-4.scala", - "phantom-self-1.scala", - "phantom-val-2.scala", - "phantom-3.scala", - "phantom-OnHList.scala", - "phantom-1.scala", - "phantom-4.scala", - "phantom-5.scala", - "phantom-methods-1.scala", - "phantom-val.scala", - "phantom-decls-2.scala", - "phantom-assume-1.scala", - "phantom-methods-10.scala", - "phantom-methods-7.scala", - "phantom-methods-6.scala", - "phantom-methods-11.scala", - "phantom-erased-methods.scala", - "phantom-methods-5.scala", - "phantom-2.scala", - "phantom-param-accessor.scala", ) ) step1.checkCompile() // Compile all files to generate the class files with tasty diff --git a/docs/_includes/features.html b/docs/_includes/features.html index 6014d8c3f531..c24856e5c87e 100644 --- a/docs/_includes/features.html +++ b/docs/_includes/features.html @@ -41,7 +41,7 @@

So, features?

Implemented - Phantom types + Unused Parameters In progress diff --git a/docs/docs/reference/phantom-types.md b/docs/docs/reference/phantom-types.md deleted file mode 100644 index c8e00eb5472c..000000000000 --- a/docs/docs/reference/phantom-types.md +++ /dev/null @@ -1,137 +0,0 @@ ---- -layout: doc-page -title: "Phantom Types" ---- - - -What is a phantom type? ------------------------ - -A phantom type is a manifestation of abstract type that has no effect on the runtime. -These are useful to prove static properties of the code using type evidences. -As they have no effect on the runtime they can be erased from the resulting code by -the compiler once it has shown the constraints hold. - -When saying that they have no effect on the runtime we do not only mean side effects -like IO, field mutation, exceptions and so on. We also imply that if a function receives -a phantom its result will not be affected by this argument. - -As phantoms do not live at runtime they cannot be subtypes of `scala.Any`, which defines -methods such as `hashCode`, `equals`, `getClass`, `asInstanceOf` and `isInstanceOf`. -All these operations cannot exist on phantoms as there will not be an underlying object -instance at runtime. At first glance this could look like a limitation, but in fact not -having `asInstanceOf` will make constraints more reliable as it will not be possible to -downcast a phantom value to fake an evidence. - -If they don't live in the universe bounded by `scala.Any` and `scala.Nothing` where do -they live? The answer is in their own type universes bounded by their phantom `Any` and `Nothing`. -In fact we allow multiple phantom universes to exist. - -```none - +-----+ +---------------+ +--------------------+ - | Any | | MyPhantom.Any | | MyOtherPhantom.Any | - +-----+ +---------------+ +--------------------+ - | | | - +----+------+ +-----+------+ ... - | | | | - +--------+ +--------+ +------+ +--------+ - | AnyRef | | AnyVal | | Inky | | Blinky | - +--------+ +--------+ +------+ +--------+ - ... ... | | - +------+ | +-------+ | - | Null | | | Pinky | | - +------+ | +-------+ | - | | | | - +------+-----+ +----+------+ ... - | | | - +---------+ +-------------------+ +------------------------+ - | Nothing | | MyPhantom.Nothing | | MyOtherPhantom.Nothing | - +---------+ +-------------------+ +------------------------+ -``` - -Inside a universe the full Dotty type system is supported. But we cannot mix types from -different universes with `&`, `|` or in type bounds. Each type must be fully defined in a single universe. - - -Implement your own phantom type -------------------------------- -Phantom types are defined by an `object` extending `scala.Phantom`. This object will represent -a universe of phantom types that is completely separated from types in `scala.Any` or other -phantom universes. We can define our phantom universe `MyPhantoms`. - -```scala -object MyPhantoms extends Phantom -``` - -```scala -package scala -trait Phantom { // only an `object` can extend this trait - protected final type Any // not a subtype of scala.Any - protected final type Nothing // subtype of every subtype of this.Any - protected final unused def assume: this.Nothing -} -``` - -The types in the phantom universe are defined by the top type `Phantom.Any` and bottom type -`Phantom.Nothing`. This means that `MyPhantoms.Any` and `MyPhantoms.Nothing` are the bounds -of the phantom types in `MyPhantoms`, these bounds are `protected` and can not be accessed -from outside `MyPhantoms` unless an alias is defined for them. - -New phantom types can be defined using `type XYZ <: OtherPhantom` (where `>: MyPhantom.Nothing` -will be inferred), this would be the equivalent of `class XYZ extends OtherClass` on types -only (no runtime definitions). Or aliased with `type MyAny = OtherPhantom`. Within `MyPhantoms` -it is possible to refer to `MyPhantoms.Any` and `MyPhantoms.Nothing` with `this.Any` and -`this.Nothing` (or just `Any` and `Nothing` but not recommended). Using this we will define -the four phantoms: `Inky`, `Blinky`, `Pinky` and `Clyde`. - -```scala -object MyPhantoms extends Phantom { - type Inky <: this.Any - type Blinky <: this.Any - type Pinky <: Inky - type Clyde <: Pinky -} -``` - -Values of phantom type can be created using the `protected def assume`. This value can be -used as a value of this phantom type as its type is `this.Nothing` (or `MyPhantoms.Nothing`). -Usually this value will be used to define a `implicit def` that returns the phantom with a more -precise type. In our example we will only create values of type `Pinky` and `Clyde` - -```scala -object MyPhantoms extends Phantom { - ... // Type definition - - unused def pinky: Pinky = assume - unused def clyde: Clyde = assume -} -``` - -### Using the phantoms - -For the user of the phantom type there is almost no difference, except for stronger type guarantees. -We can look at the following simple application: - -```scala -import MyPhantoms._ -object MyApp { - def run(unused phantom: Inky) = println("run") - def hide(unused phantom: Blinky) = println("run") - - run(pinky) - run(clyde) -} -``` - -Note that given the way we defined the phantoms it is impossible to call `hide` as we did not -expose any value of type `Blinky` to the user. We cannot call `hide(MyPhantoms.assume)` as -`assume` is protected, `hide(null.asInstanceOf[Blinky])` does not compile because it is impossible -to cast to a phantom and `hide(throw new Exception)` (or `hide(???)`) does not compile as `throw` of -type `scala.Nothing` is not in the same type universe as `Blinky`. Good, we caught all possible -mistakes before when compiling the code, no surprises at runtime (hopefully not in production). - - -What happens with Phantoms at runtime? --------------------------------------- - -All phantoms are erased using the `unused` keyword. They will simply not exist at runtime. diff --git a/docs/docs/reference/unused-terms.md b/docs/docs/reference/unused-parameters.md similarity index 100% rename from docs/docs/reference/unused-terms.md rename to docs/docs/reference/unused-parameters.md diff --git a/docs/sidebar.yml b/docs/sidebar.yml index caa4d3c5b921..123b97df7785 100644 --- a/docs/sidebar.yml +++ b/docs/sidebar.yml @@ -27,8 +27,6 @@ sidebar: url: docs/reference/implicit-function-types.html - title: Dependent Function Types url: docs/reference/dependent-function-types.html - - title: Phantom Types - url: docs/reference/phantom-types.html - title: Literal Singleton Types url: docs/reference/singleton-types.html - title: Enums diff --git a/library/src/dotty/runtime/ErasedPhantom.scala b/library/src/dotty/runtime/ErasedPhantom.scala deleted file mode 100644 index 8aac49a15e3b..000000000000 --- a/library/src/dotty/runtime/ErasedPhantom.scala +++ /dev/null @@ -1,4 +0,0 @@ -package dotty.runtime - -/** Type representing an erased phantom type */ -final abstract class ErasedPhantom diff --git a/library/src/scala/Phantom.scala b/library/src/scala/Phantom.scala deleted file mode 100644 index 4454a64cfe51..000000000000 --- a/library/src/scala/Phantom.scala +++ /dev/null @@ -1,12 +0,0 @@ -/* Defined synthetically -package scala - -trait Phantom { - /** Phantom.Any does not extend scala.Any */ - protected /*final*/ trait Any - - protected final trait Nothing extends this.Any - - protected final def assume: this.Nothing -} -*/ diff --git a/tests/generic-java-signatures/phantom.check b/tests/generic-java-signatures/phantom.check deleted file mode 100644 index bf6757ea2b50..000000000000 --- a/tests/generic-java-signatures/phantom.check +++ /dev/null @@ -1,3 +0,0 @@ -public int MyOtherPhantom$.f1(int,int) -U <: java.lang.Object -T <: dotty.runtime.ErasedPhantom diff --git a/tests/generic-java-signatures/phantom.scala b/tests/generic-java-signatures/phantom.scala deleted file mode 100644 index c9511bd682d3..000000000000 --- a/tests/generic-java-signatures/phantom.scala +++ /dev/null @@ -1,21 +0,0 @@ -object MyOtherPhantom extends Phantom { - type MyPhantom[V] <: this.Any - unused def myPhantom[X]: MyPhantom[X] = assume - - def f1[U, T <: MyPhantom[U]](a: Int, c: Int)(unused b: T): Int = a - - def f2 = { - f1(3 ,2)(myPhantom[Int]) - } -} - -object Test { - def main(args: Array[String]): Unit = { - val f1 = MyOtherPhantom.getClass.getMethods.find(_.getName.endsWith("f1")).get - val tParams = f1.getTypeParameters - println(f1.toGenericString) - tParams.foreach { tp => - println(tp.getName + " <: " + tp.getBounds.map(_.getTypeName).mkString(", ")) - } - } -} diff --git a/tests/neg-custom-args/allow-double-bindings/phantom-overload-2.scala b/tests/neg-custom-args/allow-double-bindings/phantom-overload-2.scala deleted file mode 100644 index 0f2710b873ba..000000000000 --- a/tests/neg-custom-args/allow-double-bindings/phantom-overload-2.scala +++ /dev/null @@ -1,21 +0,0 @@ - -class phantomOverload2 { - import Boo._ - - def foo1() = ??? - def foo1(unused x: A) = ??? // error - def foo1(unused x1: B)(unused x2: N) = ??? // error - - def foo2(x1: Int)(unused x2: A) = ??? - def foo2(unused x1: A)(x2: Int) = ??? // error - def foo2(unused x1: N)(unused x2: A)(x3: Int) = ??? // error - - def foo3(unused x1: Int, x2: A) = ??? - def foo3(unused x1: Int, x2: A)(unused x3: A) = ??? // error -} - -object Boo extends Phantom { - type A <: this.Any - type B <: this.Any - type N = this.Nothing -} diff --git a/tests/neg-custom-args/allow-double-bindings/phantom-overload.scala b/tests/neg-custom-args/allow-double-bindings/phantom-overload.scala deleted file mode 100644 index 0d6eab761c71..000000000000 --- a/tests/neg-custom-args/allow-double-bindings/phantom-overload.scala +++ /dev/null @@ -1,28 +0,0 @@ - -class phantomOverload { - import Boo._ - import Boo2._ - - def foo1(): A = nothing - def foo1(): B = nothing // error - def foo1(): C = nothing2 // error - def foo1(): N = nothing // error - - def foo2(unused x: A) = ??? - def foo2(unused x: A) = ??? // error - def foo2(unused x: B) = ??? // error - def foo2(unused x: C) = ??? // error - def foo2(unused x: N) = ??? // error -} - -object Boo extends Phantom { - type A <: this.Any - type B <: this.Any - type N = this.Nothing - def nothing: this.Nothing = assume -} - -object Boo2 extends Phantom { - type C <: this.Any - def nothing2: this.Nothing = assume -} \ No newline at end of file diff --git a/tests/neg/phantom-AndOr.scala b/tests/neg/phantom-AndOr.scala deleted file mode 100644 index 934bf037e51b..000000000000 --- a/tests/neg/phantom-AndOr.scala +++ /dev/null @@ -1,18 +0,0 @@ - -class BooFunDef1 { - import Boo._ - - def fun1(b: BooAny | Any) = ??? // error - def fun2(b: BooAny | Any | Any) = ??? // error // error - def fun3(b: Any | BooAny | Any) = ??? // error - def fun4(b: BooAny | BooAny | Any) = ??? // error - - def fun5(b: BooAny & Any) = ??? // error - def fun6(b: Any & BooAny & Any) = ??? // error - def fun7(b: BooAny & Any & Any) = ??? // error // error - def fun8(b: Any & Any & BooAny) = ??? // error -} - -object Boo extends Phantom { - type BooAny = this.Any -} diff --git a/tests/neg/phantom-Eq.scala b/tests/neg/phantom-Eq.scala deleted file mode 100644 index e18e9f1701be..000000000000 --- a/tests/neg/phantom-Eq.scala +++ /dev/null @@ -1,38 +0,0 @@ -/* This is a example of how to implement Eq using erasable phantom types. - * - * See also: ../pos/phantomEq.scala - */ - -object PhantomEqTest { - import EqUtil._ - - "abc" === "abc" - 1 === 4 - - 1 === "abc" // error - "ghi" === 4 // error - 0 === Nil // error - List(1, 2) === 1 // error - List(1, 2) === "" // error - -} - -object EqUtil extends Phantom { - - type PhantomEq[-L, -R] <: this.Any - type PhantomEqEq[T] = PhantomEq[T, T] - - implicit class EqualsDeco[T](val x: T) extends AnyVal { - def ===[U] (y: U)(implicit unused ce: PhantomEq[T, U]) = x.equals(y) - } - - implicit unused def eqString: PhantomEqEq[String] = assume - implicit unused def eqInt: PhantomEqEq[Int] = assume - implicit unused def eqDouble: PhantomEqEq[Double] = assume - - implicit unused def eqByteNum: PhantomEq[Byte, Number] = assume - implicit unused def eqNumByte: PhantomEq[Number, Byte] = assume - - implicit unused def eqSeq[T, U](implicit eq: PhantomEq[T, U]): PhantomEq[Seq[T], Seq[U]] = assume - -} diff --git a/tests/neg/phantom-assume-1.scala b/tests/neg/phantom-assume-1.scala deleted file mode 100644 index 53a1d1fdf786..000000000000 --- a/tests/neg/phantom-assume-1.scala +++ /dev/null @@ -1,4 +0,0 @@ -object Boo extends Phantom { - type BooAny = this.Any - def assume1: BooAny = assume() // error: method assume in trait Phantom does not take parameters -} diff --git a/tests/neg/phantom-bottom.scala b/tests/neg/phantom-bottom.scala deleted file mode 100644 index 7f6f2c2ff333..000000000000 --- a/tests/neg/phantom-bottom.scala +++ /dev/null @@ -1,25 +0,0 @@ - -class BooFunDef1 { - import Boo._ - - def fun0(x: Foo): x.Y = Boo.nothing - - def fun1(x: Foo): x.Y = ??? // error - def fun2(x: Foo): x.Y = null // error - def fun3(x: Foo): x.Y = Boo2.nothing // error -} - -class Foo { - type Y <: Boo.BooAny -} - -object Boo extends Phantom { - type BooAny = this.Any - type BooNothing = this.Nothing - def nothing: BooNothing = assume -} - -object Boo2 extends Phantom { - type BooNothing2 = this.Nothing - def nothing: BooNothing2 = assume -} \ No newline at end of file diff --git a/tests/neg/phantom-classOf-1.scala b/tests/neg/phantom-classOf-1.scala deleted file mode 100644 index 9e25d1b1a92f..000000000000 --- a/tests/neg/phantom-classOf-1.scala +++ /dev/null @@ -1,10 +0,0 @@ - -class phantomClassOf { - classOf[BooAny] // error - classOf[BooNothing] // error -} - -object Boo extends Phantom { - type BooAny = this.Any - type BooNothing = this.Nothing -} diff --git a/tests/neg/phantom-classOf-2.scala b/tests/neg/phantom-classOf-2.scala deleted file mode 100644 index 1d3b0e3752f3..000000000000 --- a/tests/neg/phantom-classOf-2.scala +++ /dev/null @@ -1,10 +0,0 @@ - -class phantomClassOf { - type Blinky <: Boo.BooAny - - classOf[Blinky] // error -} - -object Boo extends Phantom { - type BooAny = this.Any -} diff --git a/tests/neg/phantom-evidence.scala b/tests/neg/phantom-evidence.scala deleted file mode 100644 index aae2972a70ff..000000000000 --- a/tests/neg/phantom-evidence.scala +++ /dev/null @@ -1,27 +0,0 @@ -/** In this implementation variant of =:= (called =::=) we erase all instantiations and definitions of =::= */ -object WithNormalState extends Phantom { - - type =::=[From, To] <: this.Any - - implicit inline def tpEquals[A]: A =::= A = assume - - trait State - sealed trait On extends State - sealed trait Off extends State - - object Instance { - def newInstance(): Instance[Off] = new Instance[Off] - } - class Instance[S <: State] private { - def getOnInstance(implicit ev: S =::= Off): Instance[On] = new Instance[On] - def getOffInstance(implicit ev: S =::= On): Instance[Off] = new Instance[Off] - } - - def run() = { - val instance = Instance.newInstance() - instance.getOffInstance // error - instance.getOnInstance.getOnInstance // error - } - -} - diff --git a/tests/neg/phantom-expr.scala b/tests/neg/phantom-expr.scala deleted file mode 100644 index eff415121dae..000000000000 --- a/tests/neg/phantom-expr.scala +++ /dev/null @@ -1,49 +0,0 @@ - -class Foo { - import Boo._ - import Boo1._ - - type Blinky <: BooAny - type Inky <: BooAny - - val blinky = Boo.boo[Blinky] - val inky = Boo.boo[Inky] - - val b = true - def fooIf1 = - if (b) blinky - else "" // error - - def fooIf2 = - if (b) "" - else blinky // error - - def fooIf3 = - if (b) boo1 - else blinky // error - - def fooMatch1 = blinky match { // error - case _: Blinky => () - } - def fooMatch2 = 1 match { case 1 => 2 - case _ => blinky // error - } - def fooMatch3 = 1 match { - case 1 => boo1 - case _ => blinky // error - } - def fooTry = - try 1 - catch { case ex: Exception => blinky // error - } -} - -object Boo extends Phantom { - type BooAny = this.Any - def boo[B <: BooAny]: B = assume -} - -object Boo1 extends Phantom { - type Boo1Any = this.Any - def boo1: Boo1Any = assume -} diff --git a/tests/neg/phantom-fun-app.scala b/tests/neg/phantom-fun-app.scala deleted file mode 100644 index 1c403da61806..000000000000 --- a/tests/neg/phantom-fun-app.scala +++ /dev/null @@ -1,24 +0,0 @@ - -class phantomFunApp { - import Boo._ // Note: this is dangerous as it imports Boo.Any as Any - - def foo1(unused a: Any) = ??? - def foo2(unused b: BooAny) = ??? - - foo1(1) - foo1(boo[Blinky]) // error - foo1(boo[Pinky]) // error - - foo2(boo[Blinky]) - foo2(boo[Pinky]) - foo2(1) // error - foo2("abc") // error - foo2(???) // error -} - -object Boo extends Phantom { - type BooAny = this.Any - type Blinky <: BooAny - type Pinky <: Blinky - def boo[B <: BooAny]: B = assume -} diff --git a/tests/neg/phantom-in-value-class.scala b/tests/neg/phantom-in-value-class.scala deleted file mode 100644 index c154f8d7582e..000000000000 --- a/tests/neg/phantom-in-value-class.scala +++ /dev/null @@ -1,11 +0,0 @@ -import MyPhantom._ - - -class Cursed1(unused val p: Boo) extends AnyVal // error - -class Cursed2(val n: Int)(val a: Int) extends AnyVal // error - -object MyPhantom extends Phantom { - type Boo <: super[MyPhantom].Any - def boo: Boo = assume -} diff --git a/tests/neg/phantom-instanceOf-1.scala b/tests/neg/phantom-instanceOf-1.scala deleted file mode 100644 index 7135c4281563..000000000000 --- a/tests/neg/phantom-instanceOf-1.scala +++ /dev/null @@ -1,11 +0,0 @@ - -class phantomInstanceOf1 { - null.asInstanceOf[Boo.Any] // error - null.asInstanceOf[Boo.Nothing] // error - "".asInstanceOf[Boo.Any] // error - "".asInstanceOf[Boo.Nothing] // error -} - -object Boo extends Phantom { - def boo[B <: Boo.Any]: B = assume -} diff --git a/tests/neg/phantom-instanceOf-2.scala b/tests/neg/phantom-instanceOf-2.scala deleted file mode 100644 index c4164618623f..000000000000 --- a/tests/neg/phantom-instanceOf-2.scala +++ /dev/null @@ -1,14 +0,0 @@ - -class phantomInstanceOf2 { - import Boo._ - boo[Blinky].asInstanceOf[Any] // error - boo[Blinky].asInstanceOf[Nothing] // error - boo[Blinky].asInstanceOf[Blinky] // error - boo[Blinky].asInstanceOf[BooAny] // error -} - -object Boo extends Phantom { - type BooAny <: this.Any - type Blinky <: this.Any - def boo[B <: this.Any]: B = assume -} diff --git a/tests/neg/phantom-multiversal-AndOr.scala b/tests/neg/phantom-multiversal-AndOr.scala deleted file mode 100644 index c7ff53ae01be..000000000000 --- a/tests/neg/phantom-multiversal-AndOr.scala +++ /dev/null @@ -1,21 +0,0 @@ - -class BooFunDef1 { - import Universe1._ - import UniverseA._ - - def fun1(unused b: One | A) = ??? // error - def fun2(unused b: A | One) = ??? // error - def fun3(unused b: A | One | Any) = ??? // error // error - - def fun4(unused b: A & One) = ??? // error - def fun5(unused b: One & A) = ??? // error - def fun6(unused b: A & One & Any) = ??? // error // error -} - -object Universe1 extends Phantom { - type One <: this.Any -} - -object UniverseA extends Phantom { - type A <: this.Any -} diff --git a/tests/neg/phantom-multiversal-type-param-bounds-1.scala b/tests/neg/phantom-multiversal-type-param-bounds-1.scala deleted file mode 100644 index db3a5c1c3b63..000000000000 --- a/tests/neg/phantom-multiversal-type-param-bounds-1.scala +++ /dev/null @@ -1,18 +0,0 @@ - -class phantomTypeParamBounds1 { - import Universe1._ - import UniverseA._ - - def fun1[X >: OneNothing <: AAny] = ??? // error - def fun2[X >: ANothing <: OneAny] = ??? // error -} - -object Universe1 extends Phantom { - type OneAny = this.Any - type OneNothing = this.Nothing -} - -object UniverseA extends Phantom { - type AAny = this.Any - type ANothing = this.Nothing -} diff --git a/tests/neg/phantom-multiversal-type-param-bounds-2.scala b/tests/neg/phantom-multiversal-type-param-bounds-2.scala deleted file mode 100644 index 0e085578955b..000000000000 --- a/tests/neg/phantom-multiversal-type-param-bounds-2.scala +++ /dev/null @@ -1,22 +0,0 @@ - -class phantomTypeParamBounds2 { - import Universe1._ - import UniverseA._ - - def fun1[X <: One & A] = ??? // error - def fun2[X <: One | A] = ??? // error - def fun3[X >: OneNothing & ANothing] = ??? // error - def fun4[X >: OneNothing | ANothing] = ??? // error - - def fun5[X >: One & A <: One & A] = ??? // error // error -} - -object Universe1 extends Phantom { - type One <: this.Any - type OneNothing = this.Nothing -} - -object UniverseA extends Phantom { - type A <: this.Any - type ANothing = this.Nothing -} diff --git a/tests/neg/phantom-multiversal.scala b/tests/neg/phantom-multiversal.scala deleted file mode 100644 index 5164fc21e2a5..000000000000 --- a/tests/neg/phantom-multiversal.scala +++ /dev/null @@ -1,35 +0,0 @@ - -class BooFunDef1 { - import Universe1._ - import UniverseA._ - - fun1(one, two) - fun1(one, b) // error - fun1(b, a) // error // error - - funA(a, b) - funA(a, one) // error - funA(two, one) // error // error - - funMulti(a, one, 42) - funMulti(a, b, 42) // error - funMulti(one, two, one) // error // error - - def fun1(unused x: One, y: Two) = ??? - def funA(unused k: A, l: B) = ??? - def funMulti(unused k: A, x: One, i: Int) = ??? -} - -object Universe1 extends Phantom { - type One = this.Any - type Two <: One - def one: One = assume - def two: Two = assume -} - -object UniverseA extends Phantom { - type A = this.Any - type B <: A - def a: A = assume - def b: B = assume -} diff --git a/tests/neg/phantom-trait-1.scala b/tests/neg/phantom-trait-1.scala deleted file mode 100644 index bdf2429d56eb..000000000000 --- a/tests/neg/phantom-trait-1.scala +++ /dev/null @@ -1,4 +0,0 @@ - -object Boo extends Phantom { - override val assume: this.Nothing = super.assume // error -} diff --git a/tests/neg/phantom-trait-2.scala b/tests/neg/phantom-trait-2.scala deleted file mode 100644 index d585db62a854..000000000000 --- a/tests/neg/phantom-trait-2.scala +++ /dev/null @@ -1,5 +0,0 @@ - -object Boo1 extends Phantom { - class A extends this.Any // error - class B extends this.Nothing // error -} diff --git a/tests/neg/phantom-trait-3.scala b/tests/neg/phantom-trait-3.scala deleted file mode 100644 index 1512e8e513b8..000000000000 --- a/tests/neg/phantom-trait-3.scala +++ /dev/null @@ -1,6 +0,0 @@ - -class Boo1 extends Phantom // error - -trait Boo2 extends Phantom // error - -object Boo3 extends Phantom diff --git a/tests/neg/phantom-trait-4.scala b/tests/neg/phantom-trait-4.scala deleted file mode 100644 index 19a7e7b670d1..000000000000 --- a/tests/neg/phantom-trait-4.scala +++ /dev/null @@ -1,23 +0,0 @@ - -class Foo { - - object Boo1 extends Phantom // error - - def foo = { - object Boo2 extends Phantom // error - 42 - } -} - -object Foo { - object Boo1 extends Phantom - - def foo = { - object Boo2 extends Phantom // error - 42 - } -} - -package foo { - object Boo1 extends Phantom -} diff --git a/tests/neg/phantom-type-param-bounds-1.scala b/tests/neg/phantom-type-param-bounds-1.scala deleted file mode 100644 index 5e2c7fe60579..000000000000 --- a/tests/neg/phantom-type-param-bounds-1.scala +++ /dev/null @@ -1,9 +0,0 @@ - -class phantomTypeParamBounds1 { - def fun5[X >: Boo.Nothing <: Any] = ??? // error - def fun6[X >: Nothing <: Boo.Any] = ??? // error -} - -object Boo extends Phantom { - def boo[B <: this.Any]: B = assume -} diff --git a/tests/neg/phantom-type-param-bounds-2.scala b/tests/neg/phantom-type-param-bounds-2.scala deleted file mode 100644 index 4f6d4ec06051..000000000000 --- a/tests/neg/phantom-type-param-bounds-2.scala +++ /dev/null @@ -1,13 +0,0 @@ - -class phantomTypeParamBounds2 { - def fun1[X <: Boo.Any & Any] = ??? // error - def fun2[X <: Boo.Any | Any] = ??? // error - def fun3[X >: Boo.Nothing & Nothing] = ??? // error - def fun4[X >: Boo.Nothing | Nothing] = ??? // error - - def fun5[X >: Boo.Any & Any <: Boo.Any & Any] = ??? // error // error -} - -object Boo extends Phantom { - def boo[B <: Boo.Any]: B = assume -} diff --git a/tests/neg/phantom-var-2.scala b/tests/neg/phantom-var-2.scala deleted file mode 100644 index 8db8fd6fe768..000000000000 --- a/tests/neg/phantom-var-2.scala +++ /dev/null @@ -1,9 +0,0 @@ - -class Foo { - unused var foo = Boo.boo // error -} - -object Boo extends Phantom { - type A <: this.Any - unused def boo: A = assume -} diff --git a/tests/neg/phantom-var.scala b/tests/neg/phantom-var.scala deleted file mode 100644 index 13647f72a0af..000000000000 --- a/tests/neg/phantom-var.scala +++ /dev/null @@ -1,9 +0,0 @@ - -class Foo { - var foo = Boo.boo // error -} - -object Boo extends Phantom { - type A <: this.Any - unused def boo: A = assume -} diff --git a/tests/neg/reference-phantom-type-1.scala b/tests/neg/reference-phantom-type-1.scala deleted file mode 100644 index 67d49b72c1d3..000000000000 --- a/tests/neg/reference-phantom-type-1.scala +++ /dev/null @@ -1,24 +0,0 @@ -object MyPhantoms extends Phantom { - type Inky <: this.Any - type Blinky <: this.Any - type Pinky <: Inky - type Clyde <: Pinky - - def pinky: Pinky = assume - def clyde: Clyde = assume -} - -import MyPhantoms._ -object MyApp { - def run(phantom: Inky) = println("run") - def hide(phantom: Blinky) = println("run") - - run(pinky) - run(clyde) - - hide(pinky) // error - hide(clyde) // error - hide(MyPhantoms.assume) // error - hide(throw new Exception) // error - hide(???) // error -} diff --git a/tests/neg/reference-phantom-type-2.scala b/tests/neg/reference-phantom-type-2.scala deleted file mode 100644 index f4c73a601d61..000000000000 --- a/tests/neg/reference-phantom-type-2.scala +++ /dev/null @@ -1,21 +0,0 @@ -object MyPhantoms extends Phantom { - type Inky <: this.Any - type Blinky <: this.Any - type Pinky <: Inky - type Clyde <: Pinky - - unused def pinky: Pinky = assume - unused def clyde: Clyde = assume -} - -import MyPhantoms._ -object MyApp { - def run(unused phantom: Inky) = println("run") - def hide(unused phantom: Blinky) = println("run") - - run(pinky) - run(clyde) - - val a: Blinky = null.asInstanceOf[Blinky] // error - hide(a) -} diff --git a/tests/pos/phantom-Eq.scala b/tests/pos/phantom-Eq.scala index a957d7ef91e7..94e2caff8786 100644 --- a/tests/pos/phantom-Eq.scala +++ b/tests/pos/phantom-Eq.scala @@ -12,21 +12,21 @@ object PhantomEq { (1: Number) === 1.toByte } -object EqUtil extends Phantom { +object EqUtil { - type PhantomEq[-L, -R] <: this.Any + type PhantomEq[-L, -R] type PhantomEqEq[T] = PhantomEq[T, T] implicit class EqualsDeco[T](val x: T) extends AnyVal { def ===[U] (y: U)(implicit unused ce: PhantomEq[T, U]) = x.equals(y) } - implicit unused def eqString: PhantomEqEq[String] = assume - implicit unused def eqInt: PhantomEqEq[Int] = assume - implicit unused def eqDouble: PhantomEqEq[Double] = assume + implicit unused def eqString: PhantomEqEq[String] = ??? + implicit unused def eqInt: PhantomEqEq[Int] = ??? + implicit unused def eqDouble: PhantomEqEq[Double] = ??? - implicit unused def eqByteNum: PhantomEq[Byte, Number] = assume - implicit unused def eqNumByte: PhantomEq[Number, Byte] = assume + implicit unused def eqByteNum: PhantomEq[Byte, Number] = ??? + implicit unused def eqNumByte: PhantomEq[Number, Byte] = ??? - implicit unused def eqSeq[T, U](implicit unused eq: PhantomEq[T, U]): PhantomEq[Seq[T], Seq[U]] = assume + implicit unused def eqSeq[T, U](implicit unused eq: PhantomEq[T, U]): PhantomEq[Seq[T], Seq[U]] = ??? } diff --git a/tests/pos/phantom-Eq2/Phantom-Eq_1.scala b/tests/pos/phantom-Eq2/Phantom-Eq_1.scala index 2fd73af56fc6..dabca2718654 100644 --- a/tests/pos/phantom-Eq2/Phantom-Eq_1.scala +++ b/tests/pos/phantom-Eq2/Phantom-Eq_1.scala @@ -1,20 +1,21 @@ /* This is a version of ../pos/phantomEq.scala that tests phantom with separate compilation */ -object EqUtil extends Phantom { +object EqUtil { - type PhantomEq[-L, -R] <: this.Any + final class PhantomEq[-L, -R] private[EqUtil]() type PhantomEqEq[T] = PhantomEq[T, T] implicit class EqualsDeco[T](val x: T) extends AnyVal { def ===[U] (y: U)(implicit unused ce: PhantomEq[T, U]) = x.equals(y) } - implicit unused def eqString: PhantomEqEq[String] = assume - implicit unused def eqInt: PhantomEqEq[Int] = assume - implicit unused def eqDouble: PhantomEqEq[Double] = assume + implicit unused def eqString: PhantomEqEq[String] = new PhantomEq[String, String] + implicit unused def eqInt: PhantomEqEq[Int] = new PhantomEq[Int, Int] + implicit unused def eqDouble: PhantomEqEq[Double] = new PhantomEq[Double, Double] - implicit unused def eqByteNum: PhantomEq[Byte, Number] = assume - implicit unused def eqNumByte: PhantomEq[Number, Byte] = assume + implicit unused def eqByteNum: PhantomEq[Byte, Number] = new PhantomEq[Byte, Number] + implicit unused def eqNumByte: PhantomEq[Number, Byte] = new PhantomEq[Number, Byte] - implicit unused def eqSeq[T, U](implicit unused eq: PhantomEq[T, U]): PhantomEq[Seq[T], Seq[U]] = assume + implicit unused def eqSeq[T, U](implicit unused eq: PhantomEq[T, U]): PhantomEq[Seq[T], Seq[U]] = + new PhantomEq[Seq[T], Seq[U]] } diff --git a/tests/pos/phantom-Evidence.scala b/tests/pos/phantom-Evidence.scala index 98f9c08c3b13..7dd8cc8a481a 100644 --- a/tests/pos/phantom-Evidence.scala +++ b/tests/pos/phantom-Evidence.scala @@ -22,7 +22,7 @@ object WithNormalState { } -object Utils extends Phantom { - type =::=[From, To] <: this.Any - implicit unused def tpEquals[A]: A =::= A = assume +object Utils { + type =::=[From, To] + implicit unused def tpEquals[A]: A =::= A = ??? } diff --git a/tests/pos/reference/phantom-types.scala b/tests/pos/reference/phantom-types.scala deleted file mode 100644 index d30d94201ece..000000000000 --- a/tests/pos/reference/phantom-types.scala +++ /dev/null @@ -1,29 +0,0 @@ -object MyPhantoms extends Phantom { - type Inky <: this.Any - type Blinky <: this.Any - type Pinky <: Inky - type Clyde <: Pinky - - unused def pinky: Pinky = assume - unused def clyde: Clyde = assume -} - -import MyPhantoms._ -object MyApp { - def run(unused phantom: Inky) = println("run") - def hide(unused phantom: Blinky) = println("run") - - run(pinky) - run(clyde) -} - -object MyOtherPhantom extends Phantom { - type MyPhantom <: this.Any - unused def myPhantom: MyPhantom = assume - - def f1(a: Int, b: Int)(unused c: MyPhantom): Int = a + b - - def f2 = { - f1(3, 2)(myPhantom) - } -} diff --git a/tests/run/phantom-1.check b/tests/run/phantom-1.check deleted file mode 100644 index 3e2c972a8273..000000000000 --- a/tests/run/phantom-1.check +++ /dev/null @@ -1 +0,0 @@ -fun1 diff --git a/tests/run/phantom-1.scala b/tests/run/phantom-1.scala deleted file mode 100644 index 3c42bf16460e..000000000000 --- a/tests/run/phantom-1.scala +++ /dev/null @@ -1,16 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - fun1(Boo.any) - } - - def fun1(unused boo: BooAny): Unit = { - println("fun1") - } -} - -object Boo extends Phantom { - type BooAny = this.Any - unused def any: BooAny = assume -} diff --git a/tests/run/phantom-2.check b/tests/run/phantom-2.check deleted file mode 100644 index 2d4b6fc3b43a..000000000000 --- a/tests/run/phantom-2.check +++ /dev/null @@ -1 +0,0 @@ -fun2 diff --git a/tests/run/phantom-2.scala b/tests/run/phantom-2.scala deleted file mode 100644 index 8d23ea35d2df..000000000000 --- a/tests/run/phantom-2.scala +++ /dev/null @@ -1,16 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - fun2(Boo.nothig) - } - - def fun2(unused bottom: BooNothing): Unit = { - println("fun2") - } -} - -object Boo extends Phantom { - type BooNothing = this.Nothing - unused def nothig: BooNothing = assume -} diff --git a/tests/run/phantom-3.check b/tests/run/phantom-3.check deleted file mode 100644 index 86802c8797d5..000000000000 --- a/tests/run/phantom-3.check +++ /dev/null @@ -1,3 +0,0 @@ -fun3 -fun3 -fun3 diff --git a/tests/run/phantom-3.scala b/tests/run/phantom-3.scala deleted file mode 100644 index 2e27431e5423..000000000000 --- a/tests/run/phantom-3.scala +++ /dev/null @@ -1,21 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - fun3(boo[Blinky], boo[Pinky]) - fun3(boo[Inky], boo[Pinky]) - fun3(boo[Pinky], boo[Casper]) - } - - def fun3(unused x1: Blinky, x2: Inky): Unit = { - println("fun3") - } -} - -object Boo extends Phantom { - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - type Casper = Pinky - unused def boo[B <: Blinky]: B = assume -} diff --git a/tests/run/phantom-4.check b/tests/run/phantom-4.check deleted file mode 100644 index 9e4c79efcee0..000000000000 --- a/tests/run/phantom-4.check +++ /dev/null @@ -1,3 +0,0 @@ -fun4 -fun4 -fun4 diff --git a/tests/run/phantom-4.scala b/tests/run/phantom-4.scala deleted file mode 100644 index 099df17966d4..000000000000 --- a/tests/run/phantom-4.scala +++ /dev/null @@ -1,22 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - fun4(3, 4, boo[Blinky], boo[Pinky]) - fun4(5, 6, boo[Inky], boo[Pinky]) - fun4(7, 8, boo[Pinky], boo[Casper]) - } - - def fun4(unused n: Int, n2: Int, top: Blinky, bottom: Pinky): Unit = { - println("fun4") - } - -} - -object Boo extends Phantom { - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - type Casper = Pinky - unused def boo[B <: Blinky]: B = assume -} diff --git a/tests/run/phantom-5.check b/tests/run/phantom-5.check deleted file mode 100644 index 019a46ac7c15..000000000000 --- a/tests/run/phantom-5.check +++ /dev/null @@ -1,3 +0,0 @@ -fun5 -fun5 -fun5 diff --git a/tests/run/phantom-5.scala b/tests/run/phantom-5.scala deleted file mode 100644 index 9a900a7e972c..000000000000 --- a/tests/run/phantom-5.scala +++ /dev/null @@ -1,22 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - fun5(boo[Blinky])(15)(boo[Pinky])(16) - fun5(boo[Inky])(17)(boo[Pinky])(18) - fun5(boo[Pinky])(19)(boo[Casper])(20) - } - - def fun5(unused top: Blinky)(n: Int)(unused bottom: Clyde)(n2: Int): Unit = { - println("fun5") - } -} - -object Boo extends Phantom { - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - type Clyde >: Pinky <: Inky - type Casper = Pinky - unused def boo[B <: Blinky]: B = assume -} diff --git a/tests/run/phantom-OnHList.scala b/tests/run/phantom-OnHList.scala index c27818199612..71ddee870dff 100644 --- a/tests/run/phantom-OnHList.scala +++ b/tests/run/phantom-OnHList.scala @@ -86,8 +86,8 @@ object Appender { // Type level "only" computation of type Out ------------------------------------------------------ -object PhantomAppender extends Phantom { - type Aux[L1 <: HList, L2 <: HList, O <: HList] <: this.Any - implicit unused def caseHNil[L <: HList]: Aux[HNil, L, L] = assume - implicit unused def caseHCons[H, T <: HList, L <: HList, O <: HList](implicit unused p: Aux[T, L, O]): Aux[H :: T, L, H :: O] = assume +object PhantomAppender { + type Aux[L1 <: HList, L2 <: HList, O <: HList] + implicit unused def caseHNil[L <: HList]: Aux[HNil, L, L] = ??? + implicit unused def caseHCons[H, T <: HList, L <: HList, O <: HList](implicit unused p: Aux[T, L, O]): Aux[H :: T, L, H :: O] = ??? } diff --git a/tests/run/phantom-assume-1.check b/tests/run/phantom-assume-1.check deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/tests/run/phantom-assume-1.scala b/tests/run/phantom-assume-1.scala deleted file mode 100644 index adfb253da70d..000000000000 --- a/tests/run/phantom-assume-1.scala +++ /dev/null @@ -1,19 +0,0 @@ - -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - foo(Boo.assume1) - foo(Boo.assume2) - foo(Boo.assume3) - } - - def foo(unused x: Boo.BooAny) = () -} - -object Boo extends Phantom { - type BooAny = this.Any - unused def assume1: BooAny = assume - unused def assume2: BooAny = this.assume - unused def assume3: BooAny = Boo.assume -} diff --git a/tests/run/phantom-decls-1.check b/tests/run/phantom-decls-1.check deleted file mode 100644 index b50ae590ec5c..000000000000 --- a/tests/run/phantom-decls-1.check +++ /dev/null @@ -1,4 +0,0 @@ -Boo1 -Boo1.polyfun1 -Boo1 -Boo1.polyfun1 diff --git a/tests/run/phantom-decls-1.scala b/tests/run/phantom-decls-1.scala deleted file mode 100644 index 5dd661d054fa..000000000000 --- a/tests/run/phantom-decls-1.scala +++ /dev/null @@ -1,24 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - new Boo1[BooAny]().polyfun1(boo[Blinky]) - new Boo1[BooAny]().polyfun1(boo[Inky]) - } - - def fun(unused top: BooAny): Unit = () - - class Boo1[P <: BooAny] { - println("Boo1") - def polyfun1(unused p1: P): Unit = { - println("Boo1.polyfun1") - } - } -} - -object Boo extends Phantom { - type BooAny = this.Any - type Blinky <: this.Any - type Inky <: Blinky - unused def boo[B <: Blinky]: B = assume -} diff --git a/tests/run/phantom-decls-2.check b/tests/run/phantom-decls-2.check deleted file mode 100644 index 12166f8878fb..000000000000 --- a/tests/run/phantom-decls-2.check +++ /dev/null @@ -1,6 +0,0 @@ -Boo2 -Boo2.polyfun1 -Boo2 -Boo2.polyfun1 -Boo2 -Boo2.polyfun1 diff --git a/tests/run/phantom-decls-2.scala b/tests/run/phantom-decls-2.scala deleted file mode 100644 index fd61a990affd..000000000000 --- a/tests/run/phantom-decls-2.scala +++ /dev/null @@ -1,26 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - new Boo2().polyfun1(boo[Blinky]) - new Boo2().polyfun1(boo[Inky]) - new Boo2().polyfun1(boo[Pinky]) - } - - class Boo2 { - println("Boo2") - type Boo3 = BooAny - def polyfun1(unused p2: Boo3): Unit = { - println("Boo2.polyfun1") - } - } -} - -object Boo extends Phantom { - type BooAny = this.Any - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - type Casper = Pinky - unused def boo[B <: this.Any]: B = assume -} diff --git a/tests/run/phantom-decls-3.check b/tests/run/phantom-decls-3.check deleted file mode 100644 index 0e209e00a5bd..000000000000 --- a/tests/run/phantom-decls-3.check +++ /dev/null @@ -1,4 +0,0 @@ -Boo3 -Boo3.polyfun1 -Boo3 -Boo3.polyfun1 diff --git a/tests/run/phantom-decls-3.scala b/tests/run/phantom-decls-3.scala deleted file mode 100644 index b3834126c0b5..000000000000 --- a/tests/run/phantom-decls-3.scala +++ /dev/null @@ -1,31 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - - new Boo3(){ - type Boo1 = BooAny - }.polyfun1(boo[Pinky]) - - new Boo3(){ - type Boo1 = Blinky - }.polyfun1(boo[Blinky]) - - } - - trait Boo3 { - println("Boo3") - type Boo1 <: BooAny - def polyfun1(unused p3: Boo1): Unit = { - println("Boo3.polyfun1") - } - } -} - -object Boo extends Phantom { - type BooAny = this.Any - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - unused def boo[B <: BooAny]: B = assume -} diff --git a/tests/run/phantom-decls-4.check b/tests/run/phantom-decls-4.check deleted file mode 100644 index ab02977bcee4..000000000000 --- a/tests/run/phantom-decls-4.check +++ /dev/null @@ -1,3 +0,0 @@ -Boo4 -Boo4 -Boo4 diff --git a/tests/run/phantom-decls-4.scala b/tests/run/phantom-decls-4.scala deleted file mode 100644 index a579c75061cf..000000000000 --- a/tests/run/phantom-decls-4.scala +++ /dev/null @@ -1,20 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - new Boo4(boo[Blinky]) - new Boo4(boo[Inky]) - new Boo4(boo[Pinky]) - } - - class Boo4(unused p4: Blinky) { - println("Boo4") - } -} - -object Boo extends Phantom { - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - unused def boo[B <: Blinky]: B = assume -} diff --git a/tests/run/phantom-decls-5.check b/tests/run/phantom-decls-5.check deleted file mode 100644 index 2a678b77b83a..000000000000 --- a/tests/run/phantom-decls-5.check +++ /dev/null @@ -1,2 +0,0 @@ -Boo5 -Boo5 diff --git a/tests/run/phantom-decls-5.scala b/tests/run/phantom-decls-5.scala deleted file mode 100644 index 26f5f8270d93..000000000000 --- a/tests/run/phantom-decls-5.scala +++ /dev/null @@ -1,19 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - new Boo5[Blinky](boo[Pinky]) - new Boo5[Pinky](boo[Pinky]) - } - - class Boo5[P <: Blinky](unused p5: P) { - println("Boo5") - } -} - -object Boo extends Phantom { - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - unused def boo[B <: Blinky]: B = assume -} diff --git a/tests/run/phantom-erased-methods.check b/tests/run/phantom-erased-methods.check deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/tests/run/phantom-erased-methods.scala b/tests/run/phantom-erased-methods.scala deleted file mode 100644 index cc37cfa2d84c..000000000000 --- a/tests/run/phantom-erased-methods.scala +++ /dev/null @@ -1,31 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - val foo = new Foo - - // check that parameters have been removed from the functions - // (would fail with NoSuchMethodException if not erased) - foo.getClass.getDeclaredMethod("fun1") - foo.getClass.getDeclaredMethod("fun2", classOf[String]) - - try { - foo.getClass.getDeclaredMethod("fun3") - assert(false) - } catch { - case _: NoSuchMethodException => // OK - } - } -} - -class Foo { - import Boo._ - def fun1(unused b: BooAny): Unit = () - def fun2(unused b: BooAny)(s: String): Unit = () - unused def fun3(): BooAny = boo -} - -object Boo extends Phantom { - type BooAny = Boo.Any - unused def boo: BooAny = assume -} diff --git a/tests/run/phantom-hk-1.check b/tests/run/phantom-hk-1.check deleted file mode 100644 index 79a820550a35..000000000000 --- a/tests/run/phantom-hk-1.check +++ /dev/null @@ -1,3 +0,0 @@ -hkFun1 -hkFun1 -hkFun1 diff --git a/tests/run/phantom-hk-1.scala b/tests/run/phantom-hk-1.scala deleted file mode 100644 index f1e688533b43..000000000000 --- a/tests/run/phantom-hk-1.scala +++ /dev/null @@ -1,27 +0,0 @@ - -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - hkFun1(boo[Blinky]) - hkFun1(boo[Inky]) - hkFun1(boo[Pinky]) - } - - type HKPhantom[X <: Blinky] = X - - def hkFun1[Y <: Blinky](unused p9: HKPhantom[Y]) = { - println("hkFun1") - } - -} - -trait Phantoms { -} - -object Boo extends Phantom { - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - unused def boo[B <: this.Any]: B = assume -} diff --git a/tests/run/phantom-hk-2.check b/tests/run/phantom-hk-2.check deleted file mode 100644 index a36ae238b71d..000000000000 --- a/tests/run/phantom-hk-2.check +++ /dev/null @@ -1,3 +0,0 @@ -hk2 -hk2 -hk2 diff --git a/tests/run/phantom-hk-2.scala b/tests/run/phantom-hk-2.scala deleted file mode 100644 index 342515c0da63..000000000000 --- a/tests/run/phantom-hk-2.scala +++ /dev/null @@ -1,24 +0,0 @@ -object Test { - import Boo._ - - type HKPhantom[X <: BooAny] = X - - def main(args: Array[String]): Unit = { - fun(hkFun2(boo[Blinky])) - fun(hkFun2(boo[Inky])) - fun(hkFun2(boo[Pinky])) - } - - def fun(unused top: BooAny): Unit = println("hk2") - - unused def hkFun2[Y <: BooAny](unused p10: HKPhantom[Y]): HKPhantom[Y] = p10 -} - - -object Boo extends Phantom { - type BooAny = Boo.Any - type Blinky <: Boo.Any - type Inky <: Blinky - type Pinky <: Inky - unused def boo[B <: Boo.Any]: B = assume -} diff --git a/tests/run/phantom-in-value-class.scala b/tests/run/phantom-in-value-class.scala deleted file mode 100644 index de4f84ea5e7b..000000000000 --- a/tests/run/phantom-in-value-class.scala +++ /dev/null @@ -1,24 +0,0 @@ -import MyPhantom._ - -object Test { - def main(args: Array[String]): Unit = { - val cursed = new Cursed(7)(boo) - val cursed2 = new Cursed(7)(boo) - foo(cursed.p) - foo(cursed2.p) - } - - def foo(unused x: Boo) = () -} - - -class Cursed(val n: Int)(unused val p: Boo) extends AnyVal - -class Cursed2[B <: Boo](val n: Int)(unused val p: B) extends AnyVal - -class Cursed3[B <: Boo](val n: Int)(unused val p1: Boo, val p2: B) extends AnyVal - -object MyPhantom extends Phantom { - type Boo <: super[MyPhantom].Any - unused def boo: Boo = assume -} diff --git a/tests/run/phantom-methods-1.check b/tests/run/phantom-methods-1.check deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/tests/run/phantom-methods-1.scala b/tests/run/phantom-methods-1.scala deleted file mode 100644 index 1d835d588336..000000000000 --- a/tests/run/phantom-methods-1.scala +++ /dev/null @@ -1,17 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - fun(phantomFun1()) - } - - def fun(unused top: BooAny): Unit = () - - unused def phantomFun1(): Pinky = boo[Pinky] -} - -object Boo extends Phantom { - type BooAny = Boo.Any - type Pinky <: Boo.Any - unused def boo[B <: Boo.Any]: B = assume -} diff --git a/tests/run/phantom-methods-10.check b/tests/run/phantom-methods-10.check deleted file mode 100644 index 5353be80d1af..000000000000 --- a/tests/run/phantom-methods-10.check +++ /dev/null @@ -1,2 +0,0 @@ -fun -pacFun4 diff --git a/tests/run/phantom-methods-10.scala b/tests/run/phantom-methods-10.scala deleted file mode 100644 index c521aba22736..000000000000 --- a/tests/run/phantom-methods-10.scala +++ /dev/null @@ -1,26 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - fun2.pacFun4(inky) - } - - def pacFun4(unused clyde: Inky) = { - println("pacFun4") - } - - unused def inky: Inky = { - println("inky") - boo[Inky] - } - - def fun2 = { - println("fun") - this - } -} - -object Boo extends Phantom { - type Inky <: this.Any - unused def boo[B <: this.Any]: B = assume -} diff --git a/tests/run/phantom-methods-11.check b/tests/run/phantom-methods-11.check deleted file mode 100644 index de1491a338a6..000000000000 --- a/tests/run/phantom-methods-11.check +++ /dev/null @@ -1,6 +0,0 @@ -fun -Fun -Fun2 -Fun2fun -Fun2 -Fun2fun2 diff --git a/tests/run/phantom-methods-11.scala b/tests/run/phantom-methods-11.scala deleted file mode 100644 index 7045ac65b837..000000000000 --- a/tests/run/phantom-methods-11.scala +++ /dev/null @@ -1,69 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - fun( - { println("x1"); boo }, - { println("x2"); boo } - )( - { println("x3"); boo } - )( - { println("x4"); boo }, - { println("x5"); boo } - ) - - new Fun( - { println("y1"); boo }, - { println("y2"); boo } - )( - { println("y3"); boo } - )( - { println("y4"); boo }, - { println("y5"); boo } - ) - - (new Fun2().fun)( - { println("z1"); boo }, - { println("z2"); boo } - )( - { println("z3"); boo } - )( - { println("z4"); boo }, - { println("z5"); boo } - ) - - (new Fun2().fun2)( - { println("w1"); boo }, - { println("w2"); boo } - )( - { println("w3"); boo } - )( - { println("w4"); boo }, - { println("w5"); boo } - ) - } - - def fun(unused x1: Inky, x2: Inky)(unused x3: Inky)(unused x4: Inky, x5: Inky) = { - println("fun") - } - - class Fun(unused y1: Inky, y2: Inky)(unused y3: Inky)(unused y4: Inky, y5: Inky) { - println("Fun") - } - - class Fun2 { - println("Fun2") - def fun(unused z1: Inky, z2: Inky)(unused z3: Inky)(unused z4: Inky, z5: Inky) = { - println("Fun2fun") - } - - def fun2[T](unused z1: Inky, z2: Inky)(unused z3: Inky)(unused z4: Inky, z5: Inky) = { - println("Fun2fun2") - } - } -} - -object Boo extends Phantom { - type Inky <: this.Any - unused def boo: Inky = assume -} diff --git a/tests/run/phantom-methods-12.check b/tests/run/phantom-methods-12.check deleted file mode 100644 index d106cf661bd5..000000000000 --- a/tests/run/phantom-methods-12.check +++ /dev/null @@ -1,8 +0,0 @@ -fun1 -y1 -y2 -fun2 -z3 -z4 -z5 -fun3 diff --git a/tests/run/phantom-methods-12.scala b/tests/run/phantom-methods-12.scala deleted file mode 100644 index 11734748cb58..000000000000 --- a/tests/run/phantom-methods-12.scala +++ /dev/null @@ -1,53 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - fun1( - { println("x1"); boo }, - { println("x2"); boo } - )( - { println("x3"); boo } - )( - { println("x4"); boo }, - { println("x5"); boo } - ) - - fun2( - { println("y1"); 1 }, - { println("y2"); 2 } - )( - { println("y3"); boo } - )( - { println("y4"); boo }, - { println("y5"); boo } - ) - - fun3( - { println("z1"); boo }, - { println("z2"); boo } - )( - { println("z3"); 4 } - )( - { println("z4"); 5 }, - { println("z5"); 6 } - ) - } - - def fun1(unused x1: Inky, x2: Inky)(unused x3: Inky)(unused x4: Inky, x5: Inky) = { - println("fun1") - } - - def fun2(x1: Int, x2: Int)(unused x3: Inky)(unused x4: Inky, x5: Inky) = { - println("fun2") - } - - def fun3(unused x1: Inky, x2: Inky)(x3: Int)(x4: Int, x5: Int) = { - println("fun3") - } - -} - -object Boo extends Phantom { - type Inky <: this.Any - unused def boo: Inky = assume -} diff --git a/tests/run/phantom-methods-13.check b/tests/run/phantom-methods-13.check deleted file mode 100644 index 14387a0f3130..000000000000 --- a/tests/run/phantom-methods-13.check +++ /dev/null @@ -1,9 +0,0 @@ -x3 -fun1 -y1 -y2 -fun2 -z3 -z4 -z5 -fun3 diff --git a/tests/run/phantom-methods-13.scala b/tests/run/phantom-methods-13.scala deleted file mode 100644 index 7989dae6166f..000000000000 --- a/tests/run/phantom-methods-13.scala +++ /dev/null @@ -1,53 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - fun1( - { println("x1"); boo }, - { println("x2"); boo } - )( - { println("x3"); 0 } - )( - { println("x4"); boo }, - { println("x5"); boo } - ) - - fun2( - { println("y1"); 1 }, - { println("y2"); 2 } - )( - { println("y3"); boo } - )( - { println("y4"); boo }, - { println("y5"); boo } - ) - - fun3( - { println("z1"); boo }, - { println("z2"); boo } - )( - { println("z3"); 4 } - )( - { println("z4"); 5 }, - { println("z5"); 6 } - ) - } - - def fun1[T](unused x1: Inky, x2: Inky)(x3: T)(unused x4: Inky, x5: Inky) = { - println("fun1") - } - - def fun2[T](x1: T, x2: T)(unused x3: Inky)(unused x4: Inky, x5: Inky) = { - println("fun2") - } - - def fun3[T](unused x1: Inky, x2: Inky)(x3: T)(x4: T, x5: T) = { - println("fun3") - } - -} - -object Boo extends Phantom { - type Inky <: this.Any - unused def boo: Inky = assume -} diff --git a/tests/run/phantom-methods-14.check b/tests/run/phantom-methods-14.check deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/tests/run/phantom-methods-14.scala b/tests/run/phantom-methods-14.scala deleted file mode 100644 index 0addf6556bd5..000000000000 --- a/tests/run/phantom-methods-14.scala +++ /dev/null @@ -1,17 +0,0 @@ -import scala.reflect.ClassTag - -object Test { - - def main(args: Array[String]): Unit = { - bar1(Foo.a) - bar2(Foo.a)(null) - } - - def bar1(unused ev: Foo.A) = () - def bar2(unused ev: Foo.A)(implicit c: ClassTag[Int]) = implicitly[ClassTag[Int]] -} - -object Foo extends Phantom { - type A <: this.Any - unused def a: A = assume -} diff --git a/tests/run/phantom-methods-2.check b/tests/run/phantom-methods-2.check deleted file mode 100644 index 1e48428f80bc..000000000000 --- a/tests/run/phantom-methods-2.check +++ /dev/null @@ -1,3 +0,0 @@ -fun -fun -fun diff --git a/tests/run/phantom-methods-2.scala b/tests/run/phantom-methods-2.scala deleted file mode 100644 index 690c233de19a..000000000000 --- a/tests/run/phantom-methods-2.scala +++ /dev/null @@ -1,21 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - fun(phantomFun2(Boo.boo[Blinky])) - fun(phantomFun2(Boo.boo[Inky])) - fun(phantomFun2(Boo.boo[Pinky])) - } - - def fun(unused top: Blinky): Unit = println("fun") - - unused def phantomFun2(unused p6: Blinky): Blinky = p6 - -} - -object Boo extends Phantom { - type Blinky <: Boo.Any - type Inky <: Blinky - type Pinky <: Inky - unused def boo[B <: Boo.Any]: B = assume -} diff --git a/tests/run/phantom-methods-3.check b/tests/run/phantom-methods-3.check deleted file mode 100644 index 1e48428f80bc..000000000000 --- a/tests/run/phantom-methods-3.check +++ /dev/null @@ -1,3 +0,0 @@ -fun -fun -fun diff --git a/tests/run/phantom-methods-3.scala b/tests/run/phantom-methods-3.scala deleted file mode 100644 index bf3711f33d78..000000000000 --- a/tests/run/phantom-methods-3.scala +++ /dev/null @@ -1,21 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - fun(phantomFun3(boo[Blinky])) - fun(phantomFun3(boo[Inky])) - fun(phantomFun3(boo[Pinky])) - } - - def fun(unused top: Blinky): Unit = println("fun") - - unused def phantomFun3[P <: Blinky](unused p7: P): Blinky = p7 - -} - -object Boo extends Phantom { - type Blinky <: Boo.Any - type Inky <: Blinky - type Pinky <: Inky - unused def boo[B <: Boo.Any]: B = assume -} diff --git a/tests/run/phantom-methods-4.check b/tests/run/phantom-methods-4.check deleted file mode 100644 index 1e48428f80bc..000000000000 --- a/tests/run/phantom-methods-4.check +++ /dev/null @@ -1,3 +0,0 @@ -fun -fun -fun diff --git a/tests/run/phantom-methods-4.scala b/tests/run/phantom-methods-4.scala deleted file mode 100644 index ce223a2103d5..000000000000 --- a/tests/run/phantom-methods-4.scala +++ /dev/null @@ -1,21 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - fun(phantomFun4(boo[Blinky])) - fun(phantomFun4(boo[Inky])) - fun(phantomFun4(boo[Blinky])) - } - - def fun(unused top: Blinky): Unit = println("fun") - - unused def phantomFun4[G <: Blinky](unused p8: G): G = p8 - -} - -object Boo extends Phantom { - type Blinky <: Boo.Any - type Inky <: Blinky - type Pinky <: Inky - unused def boo[B <: Boo.Any]: B = assume -} diff --git a/tests/run/phantom-methods-5.check b/tests/run/phantom-methods-5.check deleted file mode 100644 index 4e29067a1ff3..000000000000 --- a/tests/run/phantom-methods-5.check +++ /dev/null @@ -1,3 +0,0 @@ -customFun1 -customFun1 -customFun1 diff --git a/tests/run/phantom-methods-5.scala b/tests/run/phantom-methods-5.scala deleted file mode 100644 index 1deeab1dbb1b..000000000000 --- a/tests/run/phantom-methods-5.scala +++ /dev/null @@ -1,21 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - pacFun1(boo[Blinky]) - pacFun1(boo[Inky]) - pacFun1(boo[Pinky]) - } - - def pacFun1(unused blinky: Blinky) = { - println("customFun1") - } - -} - -object Boo extends Phantom { - type Blinky <: Boo.Any - type Inky <: Blinky - type Pinky <: Inky - unused def boo[B <: Boo.Any]: B = assume -} diff --git a/tests/run/phantom-methods-6.check b/tests/run/phantom-methods-6.check deleted file mode 100644 index 477c5c7817c8..000000000000 --- a/tests/run/phantom-methods-6.check +++ /dev/null @@ -1 +0,0 @@ -customPhantomsFun2 diff --git a/tests/run/phantom-methods-6.scala b/tests/run/phantom-methods-6.scala deleted file mode 100644 index 4d33232e2ca5..000000000000 --- a/tests/run/phantom-methods-6.scala +++ /dev/null @@ -1,19 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - pacFun2(boo[Pinky]) - } - - def pacFun2(unused pinky: Pinky) = { - println("customPhantomsFun2") - } - -} - -object Boo extends Phantom { - type Blinky <: Boo.Any - type Inky <: Blinky - type Pinky <: Inky - unused def boo[B <: Boo.Any]: B = assume -} diff --git a/tests/run/phantom-methods-7.check b/tests/run/phantom-methods-7.check deleted file mode 100644 index 002faad12556..000000000000 --- a/tests/run/phantom-methods-7.check +++ /dev/null @@ -1,2 +0,0 @@ -pacFun3 -pacFun3 diff --git a/tests/run/phantom-methods-7.scala b/tests/run/phantom-methods-7.scala deleted file mode 100644 index f6ccea93ce5a..000000000000 --- a/tests/run/phantom-methods-7.scala +++ /dev/null @@ -1,19 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - pacFun3(boo[Clyde]) - pacFun3(boo[Pinky]) - } - - def pacFun3(unused clyde: Clyde) = { - println("pacFun3") - } -} - -object Boo extends Phantom { - type Inky <: Boo.Any - type Pinky <: Inky - type Clyde >: Pinky <: Inky - unused def boo[B <: Boo.Any]: B = assume -} diff --git a/tests/run/phantom-methods-8.check b/tests/run/phantom-methods-8.check deleted file mode 100644 index 1672323fe703..000000000000 --- a/tests/run/phantom-methods-8.check +++ /dev/null @@ -1 +0,0 @@ -pacFun4 diff --git a/tests/run/phantom-methods-8.scala b/tests/run/phantom-methods-8.scala deleted file mode 100644 index cfbadf5af99d..000000000000 --- a/tests/run/phantom-methods-8.scala +++ /dev/null @@ -1,21 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - pacFun4(inky) - } - - def pacFun4(unused clyde: Inky) = { - println("pacFun4") - } - - unused def inky: Inky = { - println("inky") - Boo.boo[Inky] - } -} - -object Boo extends Phantom { - type Inky <: Boo.Any - unused def boo[B <: Boo.Any]: B = assume -} diff --git a/tests/run/phantom-methods-9.check b/tests/run/phantom-methods-9.check deleted file mode 100644 index 5353be80d1af..000000000000 --- a/tests/run/phantom-methods-9.check +++ /dev/null @@ -1,2 +0,0 @@ -fun -pacFun4 diff --git a/tests/run/phantom-methods-9.scala b/tests/run/phantom-methods-9.scala deleted file mode 100644 index dfd26dd1899d..000000000000 --- a/tests/run/phantom-methods-9.scala +++ /dev/null @@ -1,26 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - fun1().pacFun4(inky) - } - - def pacFun4(unused clyde: Inky) = { - println("pacFun4") - } - - unused def inky: Inky = { - println("inky") - boo[Inky] - } - - def fun1() = { - println("fun") - this - } -} - -object Boo extends Phantom { - type Inky <: Boo.Any - unused def boo[B <: Boo.Any]: B = assume -} diff --git a/tests/run/phantom-param-accessor.scala b/tests/run/phantom-param-accessor.scala deleted file mode 100644 index ce8a86e2d53b..000000000000 --- a/tests/run/phantom-param-accessor.scala +++ /dev/null @@ -1,15 +0,0 @@ -import Boo._ - -object Test { - def main(args: Array[String]): Unit = { - foo(new Foo(a).aVal) - } - def foo(unused a: A) = () -} - -class Foo(unused val aVal: A) - -object Boo extends Phantom { - type A = this.Nothing - unused def a: A = assume -} diff --git a/tests/run/phantom-poly-1.check b/tests/run/phantom-poly-1.check deleted file mode 100644 index e2ee46abe5fe..000000000000 --- a/tests/run/phantom-poly-1.check +++ /dev/null @@ -1,2 +0,0 @@ -polyfun1 -polyfun1 diff --git a/tests/run/phantom-poly-1.scala b/tests/run/phantom-poly-1.scala deleted file mode 100644 index a5fc9b0c1c43..000000000000 --- a/tests/run/phantom-poly-1.scala +++ /dev/null @@ -1,18 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - polyfun1() - polyfun1[Casper]() - } - - def polyfun1[P <: Casper](): Unit = { - println("polyfun1") - } - -} - -object Boo extends Phantom { - type Casper <: this.Any - unused def boo[B <: this.Any]: B = assume -} diff --git a/tests/run/phantom-poly-2.check b/tests/run/phantom-poly-2.check deleted file mode 100644 index 91de48245c31..000000000000 --- a/tests/run/phantom-poly-2.check +++ /dev/null @@ -1,3 +0,0 @@ -polyfun2 -polyfun2 -polyfun2 diff --git a/tests/run/phantom-poly-2.scala b/tests/run/phantom-poly-2.scala deleted file mode 100644 index 2f660601e8dc..000000000000 --- a/tests/run/phantom-poly-2.scala +++ /dev/null @@ -1,20 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - polyfun2(boo[Blinky]) - polyfun2(boo[Inky]) - polyfun2(boo[Pinky]) - } - - def polyfun2[G <: Blinky](unused p: G): Unit = { - println("polyfun2") - } -} - -object Boo extends Phantom { - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - unused def boo[B <: this.Any]: B = assume -} diff --git a/tests/run/phantom-poly-3.check b/tests/run/phantom-poly-3.check deleted file mode 100644 index 6bad8615924c..000000000000 --- a/tests/run/phantom-poly-3.check +++ /dev/null @@ -1,3 +0,0 @@ -polyfun3 -polyfun3 -polyfun3 diff --git a/tests/run/phantom-poly-3.scala b/tests/run/phantom-poly-3.scala deleted file mode 100644 index 2a1b8180c7cb..000000000000 --- a/tests/run/phantom-poly-3.scala +++ /dev/null @@ -1,21 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - polyfun3(boo[Blinky]) - polyfun3(boo[Inky]) - polyfun3(boo[Pinky]) - } - - def polyfun3[G <: BooAny, I <: G](unused q: I): Unit = { - println("polyfun3") - } -} - -object Boo extends Phantom { - type BooAny = this.Any - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - unused def boo[B <: Blinky]: B = assume -} diff --git a/tests/run/phantom-poly-4.check b/tests/run/phantom-poly-4.check deleted file mode 100644 index db5561ee606b..000000000000 --- a/tests/run/phantom-poly-4.check +++ /dev/null @@ -1,3 +0,0 @@ -polyfun4 -polyfun4 -polyfun4 diff --git a/tests/run/phantom-poly-4.scala b/tests/run/phantom-poly-4.scala deleted file mode 100644 index 78fea153117d..000000000000 --- a/tests/run/phantom-poly-4.scala +++ /dev/null @@ -1,21 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - polyfun4(boo[Blinky]) - polyfun4(boo[Inky]) - polyfun4(boo[Pinky]) - } - - def polyfun4[P >: BooNothing](unused p: P): Unit = { - println("polyfun4") - } -} - -object Boo extends Phantom { - type BooNothing = Boo.Nothing - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - unused def boo[B <: Blinky]: B = assume -} diff --git a/tests/run/phantom-self-1.check b/tests/run/phantom-self-1.check deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/tests/run/phantom-self-1.scala b/tests/run/phantom-self-1.scala deleted file mode 100644 index 827c4b3a5a76..000000000000 --- a/tests/run/phantom-self-1.scala +++ /dev/null @@ -1,15 +0,0 @@ -object Test { - def main(args: Array[String]): Unit = { - foo(Boo.any) - foo(Boo.any2) - } - def foo(unused a: Boo.X) = () -} - -object Boo extends Phantom with T - -trait T { self: Phantom => - type X = self.Any - unused def any: X = self.assume - unused def any2: X = assume -} diff --git a/tests/run/phantom-val-2.check b/tests/run/phantom-val-2.check deleted file mode 100644 index d00491fd7e5b..000000000000 --- a/tests/run/phantom-val-2.check +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/tests/run/phantom-val-2.scala b/tests/run/phantom-val-2.scala deleted file mode 100644 index a67e0073239a..000000000000 --- a/tests/run/phantom-val-2.scala +++ /dev/null @@ -1,25 +0,0 @@ - -object Test { - def main(args: Array[String]): Unit = { - val f = new Foo - println(1) - bar(f.foo) - bar(f.foo) - assert(!f.getClass.getDeclaredFields.exists(_.getName.startsWith("foo")), "field foo not erased") - } - - def bar(unused x: Boo.BooAny) = () -} - -class Foo { - import Boo._ - unused val foo = { - println("foo") - any - } -} - -object Boo extends Phantom { - type BooAny = this.Any - unused def any: BooAny = assume -} diff --git a/tests/run/phantom-val.check b/tests/run/phantom-val.check deleted file mode 100644 index d00491fd7e5b..000000000000 --- a/tests/run/phantom-val.check +++ /dev/null @@ -1 +0,0 @@ -1 diff --git a/tests/run/phantom-val.scala b/tests/run/phantom-val.scala deleted file mode 100644 index f13bc97c76fb..000000000000 --- a/tests/run/phantom-val.scala +++ /dev/null @@ -1,21 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - println(1) - bar(foo) - bar(foo) - } - - unused val foo = { - println("foo") - any - } - - def bar(unused a: BooAny) = () -} - -object Boo extends Phantom { - type BooAny = this.Any - unused def any: BooAny = assume -}