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/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 72a69c85431d..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,28 +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) - - 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/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 78568769305a..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)) PhantomErasure.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) @@ -401,10 +399,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 +522,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/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/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/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/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/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/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/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/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 9b267815d339..000000000000 --- a/docs/docs/reference/phantom-types.md +++ /dev/null @@ -1,181 +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 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 - - def pinky: Pinky = assume - 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(phantom: Inky) = println("run") - def hide(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? --------------------------------------- - -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. 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.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/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 1efc1bc17904..000000000000 --- a/tests/generic-java-signatures/phantom.check +++ /dev/null @@ -1,3 +0,0 @@ -public T 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 0c5983253534..000000000000 --- a/tests/generic-java-signatures/phantom.scala +++ /dev/null @@ -1,21 +0,0 @@ -object MyOtherPhantom extends Phantom { - type MyPhantom[V] <: this.Any - def myPhantom[X]: MyPhantom[X] = assume - - def f1[U, T <: MyPhantom[U]](a: Int, b: T, c: Int): T = b - - def f2 = { - f1(3, myPhantom[Int], 2) - } -} - -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 5f7dda4d4fb3..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(x: A) = ??? // error - def foo1(x1: B)(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 foo3(x1: Int, x2: A) = ??? - def foo3(x1: Int, x2: A)(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 d4de97c7bbd3..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(x: A) = ??? - def foo2(x: A) = ??? // error - def foo2(x: B) = ??? // error - def foo2(x: C) = ??? // error - def foo2(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 6d4fcb653260..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 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 def eqByteNum: PhantomEq[Byte, Number] = assume - implicit def eqNumByte: PhantomEq[Number, Byte] = assume - - implicit 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 4e6e4424acec..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(a: Any) = ??? - def foo2(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 23f225767f41..000000000000 --- a/tests/neg/phantom-in-value-class.scala +++ /dev/null @@ -1,11 +0,0 @@ -import MyPhantom._ - - -class Cursed1(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 9fc8ff8bc6df..000000000000 --- a/tests/neg/phantom-multiversal-AndOr.scala +++ /dev/null @@ -1,21 +0,0 @@ - -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 fun4(b: A & One) = ??? // error - def fun5(b: One & A) = ??? // error - def fun6(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 af1571033e8f..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(x: One, y: Two) = ??? - def funA(k: A, l: B) = ??? - def funMulti(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.scala b/tests/neg/phantom-var.scala deleted file mode 100644 index 5a7e2db3fdb6..000000000000 --- a/tests/neg/phantom-var.scala +++ /dev/null @@ -1,8 +0,0 @@ - -class Foo { - var foo = Boo.boo // error: var fields cannot have Phantom types -} - -object Boo extends Phantom { - def boo = 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-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 3bd7cbcb422f..000000000000 --- a/tests/neg/reference-phantom-type-2.scala +++ /dev/null @@ -1,20 +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(null.asInstanceOf[Blinky]) // error -} diff --git a/tests/pos/phantom-Eq.scala b/tests/pos/phantom-Eq.scala index 6ed38a4ff05e..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 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] = ??? + implicit unused def eqInt: PhantomEqEq[Int] = ??? + implicit unused def eqDouble: PhantomEqEq[Double] = ??? - implicit def eqByteNum: PhantomEq[Byte, Number] = assume - implicit def eqNumByte: PhantomEq[Number, Byte] = assume + implicit unused def eqByteNum: PhantomEq[Byte, Number] = ??? + implicit unused def eqNumByte: PhantomEq[Number, Byte] = ??? - 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]] = ??? } diff --git a/tests/pos/phantom-Eq2/Phantom-Eq_1.scala b/tests/pos/phantom-Eq2/Phantom-Eq_1.scala index 3d03c64e63a1..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 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] = 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 def eqByteNum: PhantomEq[Byte, Number] = assume - implicit 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 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]] = + new PhantomEq[Seq[T], Seq[U]] } diff --git a/tests/pos/phantom-Evidence.scala b/tests/pos/phantom-Evidence.scala index dd84f2c08383..7dd8cc8a481a 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() = { @@ -22,7 +22,7 @@ object WithNormalState { } -object Utils extends Phantom { - type =::=[From, To] <: this.Any - implicit def tpEquals[A]: A =::= A = assume +object Utils { + type =::=[From, To] + implicit unused def tpEquals[A]: A =::= A = ??? } 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 deleted file mode 100644 index 81c4815b02d0..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 - - 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) -} - -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) - } -} 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 7c5a5ecb6929..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(boo: BooAny): Unit = { - println("fun1") - } -} - -object Boo extends Phantom { - type BooAny = this.Any - 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 a29012281921..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(bottom: BooNothing): Unit = { - println("fun2") - } -} - -object Boo extends Phantom { - type BooNothing = this.Nothing - 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 aaac8bd2953f..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(x1: Blinky, x2: Inky): Unit = { - println("fun3") - } -} - -object Boo extends Phantom { - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - type Casper = Pinky - 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 d89592af1cfc..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(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 - 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 85fd49453692..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(top: Blinky)(n: Int)(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 - def boo[B <: Blinky]: B = assume -} diff --git a/tests/run/phantom-OnHList.scala b/tests/run/phantom-OnHList.scala index 0990479cd57c..71ddee870dff 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] @@ -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 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 +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 bf7efe9d4546..000000000000 --- a/tests/run/phantom-assume-1.scala +++ /dev/null @@ -1,17 +0,0 @@ - -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - Boo.assume1 - Boo.assume2 - Boo.assume3 - } -} - -object Boo extends Phantom { - type BooAny = this.Any - def assume1: BooAny = assume - def assume2: BooAny = this.assume - 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 8faedbdc1a9a..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(top: BooAny): Unit = () - - class Boo1[P <: BooAny] { - println("Boo1") - def polyfun1(p1: P): Unit = { - println("Boo1.polyfun1") - } - } -} - -object Boo extends Phantom { - type BooAny = this.Any - type Blinky <: this.Any - type Inky <: Blinky - 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 f5fe9c46f09c..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(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 - 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 5fb0bb90baa8..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(p3: Boo1): Unit = { - println("Boo3.polyfun1") - } - } -} - -object Boo extends Phantom { - type BooAny = this.Any - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - 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 696636415a0a..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(p4: Blinky) { - println("Boo4") - } -} - -object Boo extends Phantom { - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - 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 7392fcbdd63e..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](p5: P) { - println("Boo5") - } -} - -object Boo extends Phantom { - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - 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 161dc2c85336..000000000000 --- a/tests/run/phantom-erased-methods.scala +++ /dev/null @@ -1,28 +0,0 @@ -import dotty.runtime.ErasedPhantom - -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]) - - assert(foo.getClass.getDeclaredMethod("fun3").getReturnType == classOf[ErasedPhantom]) - } -} - -class Foo { - import Boo._ - def fun1(b: BooAny): Unit = () - def fun2(b: BooAny, s: String): Unit = () - def fun3(): BooAny = boo -} - -object Boo extends Phantom { - type BooAny = Boo.Any - 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 bcf1c68012c2..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](p9: HKPhantom[Y]) = { - println("hkFun1") - } - -} - -trait Phantoms { -} - -object Boo extends Phantom { - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - 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 3483e5a4b11a..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(top: BooAny): Unit = println("hk2") - - def hkFun2[Y <: BooAny](p10: HKPhantom[Y]): HKPhantom[Y] = p10 -} - - -object Boo extends Phantom { - type BooAny = Boo.Any - type Blinky <: Boo.Any - type Inky <: Blinky - type Pinky <: Inky - 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 daa93a5b31a5..000000000000 --- a/tests/run/phantom-in-value-class.scala +++ /dev/null @@ -1,22 +0,0 @@ -import MyPhantom._ - -object Test { - def main(args: Array[String]): Unit = { - val cursed = new Cursed(7)(boo) - val cursed2 = new Cursed(7)(boo) - cursed.p - cursed2.p - } -} - - -class Cursed(val n: Int)(val p: Boo) extends AnyVal - -class Cursed2[B <: Boo](val n: Int)(val p: B) extends AnyVal - -class Cursed3[B <: Boo](val n: Int)(val p1: Boo, val p2: B) extends AnyVal - -object MyPhantom extends Phantom { - type Boo <: super[MyPhantom].Any - 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.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 4888974c8e77..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(top: BooAny): Unit = () - - def phantomFun1(): Pinky = boo[Pinky] -} - -object Boo extends Phantom { - type BooAny = Boo.Any - type Pinky <: Boo.Any - 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 50cb66f41e35..000000000000 --- a/tests/run/phantom-methods-10.check +++ /dev/null @@ -1,3 +0,0 @@ -fun -inky -pacFun4 diff --git a/tests/run/phantom-methods-10.scala b/tests/run/phantom-methods-10.scala deleted file mode 100644 index 41b8ece4f827..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(clyde: Inky) = { - println("pacFun4") - } - - def inky: Inky = { - println("inky") - boo[Inky] - } - - def fun2 = { - println("fun") - this - } -} - -object Boo extends Phantom { - type Inky <: this.Any - 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 fcaa59464f2f..000000000000 --- a/tests/run/phantom-methods-11.check +++ /dev/null @@ -1,26 +0,0 @@ -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 deleted file mode 100644 index 10b15b8d7d09..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(x1: Inky, x2: Inky)(x3: Inky)(x4: Inky, x5: Inky) = { - println("fun") - } - - class Fun(y1: Inky, y2: Inky)(y3: Inky)(y4: Inky, y5: Inky) { - println("Fun") - } - - class Fun2 { - println("Fun2") - def fun(z1: Inky, z2: Inky)(z3: Inky)(z4: Inky, z5: Inky) = { - println("Fun2fun") - } - - def fun2[T](z1: Inky, z2: Inky)(z3: Inky)(z4: Inky, z5: Inky) = { - println("Fun2fun2") - } - } -} - -object Boo extends Phantom { - type Inky <: this.Any - 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 7a69fa94b7ea..000000000000 --- a/tests/run/phantom-methods-12.check +++ /dev/null @@ -1,18 +0,0 @@ -x1 -x2 -x3 -x4 -x5 -fun1 -y1 -y2 -y3 -y4 -y5 -fun2 -z1 -z2 -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 84fb8aa905ff..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(x1: Inky, x2: Inky)(x3: Inky)(x4: Inky, x5: Inky) = { - println("fun1") - } - - def fun2(x1: Int, x2: Int)(x3: Inky)(x4: Inky, x5: Inky) = { - println("fun2") - } - - def fun3(x1: Inky, x2: Inky)(x3: Int)(x4: Int, x5: Int) = { - println("fun3") - } - -} - -object Boo extends Phantom { - type Inky <: this.Any - 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 7a69fa94b7ea..000000000000 --- a/tests/run/phantom-methods-13.check +++ /dev/null @@ -1,18 +0,0 @@ -x1 -x2 -x3 -x4 -x5 -fun1 -y1 -y2 -y3 -y4 -y5 -fun2 -z1 -z2 -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 ef33c434acdb..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](x1: Inky, x2: Inky)(x3: T)(x4: Inky, x5: Inky) = { - println("fun1") - } - - def fun2[T](x1: T, x2: T)(x3: Inky)(x4: Inky, x5: Inky) = { - println("fun2") - } - - def fun3[T](x1: Inky, x2: Inky)(x3: T)(x4: T, x5: T) = { - println("fun3") - } - -} - -object Boo extends Phantom { - type Inky <: this.Any - 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 d149ddf1efed..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(ev: Foo.A) = () - def bar2(ev: Foo.A)(implicit c: ClassTag[Int]) = implicitly[ClassTag[Int]] -} - -object Foo extends Phantom { - type A <: this.Any - 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 7849f68d5303..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(top: Blinky): Unit = println("fun") - - def phantomFun2(p6: Blinky): Blinky = p6 - -} - -object Boo extends Phantom { - type Blinky <: Boo.Any - type Inky <: Blinky - type Pinky <: Inky - 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 cc43ed3b9acd..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(top: Blinky): Unit = println("fun") - - def phantomFun3[P <: Blinky](p7: P): Blinky = p7 - -} - -object Boo extends Phantom { - type Blinky <: Boo.Any - type Inky <: Blinky - type Pinky <: Inky - 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 50145d3a4641..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(top: Blinky): Unit = println("fun") - - def phantomFun4[G <: Blinky](p8: G): G = p8 - -} - -object Boo extends Phantom { - type Blinky <: Boo.Any - type Inky <: Blinky - type Pinky <: Inky - 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 9dccf849f9ae..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(blinky: Blinky) = { - println("customFun1") - } - -} - -object Boo extends Phantom { - type Blinky <: Boo.Any - type Inky <: Blinky - type Pinky <: Inky - 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 2de694a571c1..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(pinky: Pinky) = { - println("customPhantomsFun2") - } - -} - -object Boo extends Phantom { - type Blinky <: Boo.Any - type Inky <: Blinky - type Pinky <: Inky - 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 9e76501d99a3..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(clyde: Clyde) = { - println("pacFun3") - } -} - -object Boo extends Phantom { - type Inky <: Boo.Any - type Pinky <: Inky - type Clyde >: Pinky <: Inky - 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 1046cb49e89d..000000000000 --- a/tests/run/phantom-methods-8.check +++ /dev/null @@ -1,2 +0,0 @@ -inky -pacFun4 diff --git a/tests/run/phantom-methods-8.scala b/tests/run/phantom-methods-8.scala deleted file mode 100644 index 21eeae6bfb5b..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(clyde: Inky) = { - println("pacFun4") - } - - def inky: Inky = { - println("inky") - Boo.boo[Inky] - } -} - -object Boo extends Phantom { - type Inky <: Boo.Any - 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 50cb66f41e35..000000000000 --- a/tests/run/phantom-methods-9.check +++ /dev/null @@ -1,3 +0,0 @@ -fun -inky -pacFun4 diff --git a/tests/run/phantom-methods-9.scala b/tests/run/phantom-methods-9.scala deleted file mode 100644 index c02d7cf9af03..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(clyde: Inky) = { - println("pacFun4") - } - - def inky: Inky = { - println("inky") - boo[Inky] - } - - def fun1() = { - println("fun") - this - } -} - -object Boo extends Phantom { - type Inky <: Boo.Any - 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 eab1bd13d17e..000000000000 --- a/tests/run/phantom-param-accessor.scala +++ /dev/null @@ -1,14 +0,0 @@ -import Boo._ - -object Test { - def main(args: Array[String]): Unit = { - new Foo(a).aVal - } -} - -class Foo(val aVal: A) - -object Boo extends Phantom { - type A = this.Nothing - def 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 822556f7a0ed..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 - 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 6a519573a8a0..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](p: G): Unit = { - println("polyfun2") - } -} - -object Boo extends Phantom { - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - 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 65dbd137f9cf..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](q: I): Unit = { - println("polyfun3") - } -} - -object Boo extends Phantom { - type BooAny = this.Any - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - 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 697686fa8390..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](p: P): Unit = { - println("polyfun4") - } -} - -object Boo extends Phantom { - type BooNothing = Boo.Nothing - type Blinky <: this.Any - type Inky <: Blinky - type Pinky <: Inky - 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 9c112ff57c96..000000000000 --- a/tests/run/phantom-self-1.scala +++ /dev/null @@ -1,14 +0,0 @@ -object Test { - def main(args: Array[String]): Unit = { - Boo.any - Boo.any2 - } -} - -object Boo extends Phantom with T - -trait T { self: Phantom => - type X = self.Any - def any: X = self.assume - 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 06b2967cef34..000000000000 --- a/tests/run/phantom-val-2.check +++ /dev/null @@ -1,2 +0,0 @@ -foo -1 diff --git a/tests/run/phantom-val-2.scala b/tests/run/phantom-val-2.scala deleted file mode 100644 index 0fa3bb2ebf42..000000000000 --- a/tests/run/phantom-val-2.scala +++ /dev/null @@ -1,23 +0,0 @@ - -object Test { - def main(args: Array[String]): Unit = { - val f = new Foo - println(1) - f.foo - f.foo - assert(!f.getClass.getDeclaredFields.exists(_.getName.startsWith("foo")), "field foo not erased") - } -} - -class Foo { - import Boo._ - val foo = { - println("foo") - any - } -} - -object Boo extends Phantom { - type BooAny = this.Any - def any: BooAny = assume -} diff --git a/tests/run/phantom-val.check b/tests/run/phantom-val.check deleted file mode 100644 index 06b2967cef34..000000000000 --- a/tests/run/phantom-val.check +++ /dev/null @@ -1,2 +0,0 @@ -foo -1 diff --git a/tests/run/phantom-val.scala b/tests/run/phantom-val.scala deleted file mode 100644 index e514e8e312e4..000000000000 --- a/tests/run/phantom-val.scala +++ /dev/null @@ -1,20 +0,0 @@ -object Test { - import Boo._ - - def main(args: Array[String]): Unit = { - println(1) - foo - foo - - } - - val foo = { - println("foo") - any - } -} - -object Boo extends Phantom { - type BooAny = this.Any - def any: BooAny = assume -}