diff --git a/.gitignore b/.gitignore index af401d5680ed..90009066ca8f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.class *.log +*~ # sbt specific dist/* diff --git a/src/dotty/tools/dotc/Compiler.scala b/src/dotty/tools/dotc/Compiler.scala index c2f21f63908a..286ed34564ac 100644 --- a/src/dotty/tools/dotc/Compiler.scala +++ b/src/dotty/tools/dotc/Compiler.scala @@ -5,6 +5,7 @@ import core._ import Contexts._ import Periods._ import Symbols._ +import Scopes._ import typer.{FrontEnd, Typer, Mode, ImportInfo} import reporting.ConsoleReporter import dotty.tools.dotc.core.Phases.Phase @@ -28,16 +29,28 @@ class Compiler { runId += 1; runId } + /** Produces the following contexts, from outermost to innermost + * + * bootStrap: A context with next available runId and a scope consisting of + * the RootPackage _root_ + * start A context with RootClass as owner and the necessary initializations + * for type checking. + * imports For each element of RootImports, an import context + */ def rootContext(implicit ctx: Context): Context = { ctx.definitions.init(ctx) ctx.usePhases(phases) - val start = ctx.fresh + val rootScope = new MutableScope + val bootstrap = ctx.fresh .withPeriod(Period(nextRunId, FirstPhaseId)) + .withScope(rootScope) + rootScope.enter(ctx.definitions.RootPackage)(bootstrap) + val start = bootstrap.fresh .withOwner(defn.RootClass) .withTyper(new Typer) .withNewMode(Mode.ImplicitsEnabled) .withTyperState(new MutableTyperState(ctx.typerState, new ConsoleReporter()(ctx), isCommittable = true)) - ctx.definitions.init(start) + ctx.definitions.init(start) // set context of definitions to start def addImport(ctx: Context, sym: Symbol) = ctx.fresh.withImportInfo(ImportInfo.rootImport(sym)(ctx)) (start.withRunInfo(new RunInfo(start)) /: defn.RootImports)(addImport) diff --git a/src/dotty/tools/dotc/config/Printers.scala b/src/dotty/tools/dotc/config/Printers.scala index 853049b047b2..d06eb2ece5fc 100644 --- a/src/dotty/tools/dotc/config/Printers.scala +++ b/src/dotty/tools/dotc/config/Printers.scala @@ -22,6 +22,7 @@ object Printers { val unapp: Printer = noPrinter val completions = noPrinter val gadts = noPrinter + val hk = noPrinter val incremental = noPrinter val config = noPrinter } \ No newline at end of file diff --git a/src/dotty/tools/dotc/core/Definitions.scala b/src/dotty/tools/dotc/core/Definitions.scala index a58bfc05816d..0ec770149283 100644 --- a/src/dotty/tools/dotc/core/Definitions.scala +++ b/src/dotty/tools/dotc/core/Definitions.scala @@ -359,12 +359,6 @@ class Definitions { */ def hkTrait(vcs: List[Int]) = { - def varianceSuffix(v: Int) = v match { - case -1 => "N" - case 0 => "I" - case 1 => "P" - } - def varianceFlags(v: Int) = v match { case -1 => Contravariant case 0 => Covariant @@ -375,14 +369,13 @@ class Definitions { def complete(denot: SymDenotation)(implicit ctx: Context): Unit = { val cls = denot.asClass.classSymbol val paramDecls = newScope - for ((v, i) <- vcs.zipWithIndex) - newTypeParam(cls, tpnme.higherKindedParamName(i), varianceFlags(v), paramDecls) + for (i <- 0 until vcs.length) + newTypeParam(cls, tpnme.higherKindedParamName(i), EmptyFlags, paramDecls) denot.info = ClassInfo(ScalaPackageClass.thisType, cls, List(ObjectClass.typeRef), paramDecls) } } - val traitName = - tpnme.higherKindedTraitName(vcs.length) ++ (vcs map varianceSuffix).mkString + val traitName = tpnme.higherKindedTraitName(vcs) def createTrait = { val cls = newClassSymbol( diff --git a/src/dotty/tools/dotc/core/NameOps.scala b/src/dotty/tools/dotc/core/NameOps.scala index 1a9e5eddb6b3..b9df8f6ed162 100644 --- a/src/dotty/tools/dotc/core/NameOps.scala +++ b/src/dotty/tools/dotc/core/NameOps.scala @@ -168,6 +168,19 @@ object NameOps { } } + /** The variances of the higherKinded parameters of the trait named + * by this name. + * @pre The name is a higher-kinded trait name, i.e. it starts with HK_TRAIT_PREFIX + */ + def hkVariances: List[Int] = { + def varianceOfSuffix(suffix: Char): Int = { + val idx = tpnme.varianceSuffixes.indexOf(suffix) + assert(idx >= 0) + idx - 1 + } + name.drop(tpnme.HK_TRAIT_PREFIX.length).toList.map(varianceOfSuffix) + } + /** If name length exceeds allowable limit, replace part of it by hash */ def compactified(implicit ctx: Context): TermName = termName(compactify(name.toString)) } diff --git a/src/dotty/tools/dotc/core/StdNames.scala b/src/dotty/tools/dotc/core/StdNames.scala index 6cd9da4b5874..3982c51f00ee 100644 --- a/src/dotty/tools/dotc/core/StdNames.scala +++ b/src/dotty/tools/dotc/core/StdNames.scala @@ -248,6 +248,7 @@ object StdNames { val SPECIALIZED_INSTANCE: N = "specInstance$" val THIS: N = "_$this" val HK_PARAM_PREFIX: N = "_$hk$" + val HK_TRAIT_PREFIX: N = "$HigherKinded$" final val Nil: N = "Nil" final val Predef: N = "Predef" @@ -281,7 +282,6 @@ object StdNames { val ConstantType: N = "ConstantType" val ExistentialTypeTree: N = "ExistentialTypeTree" val Flag : N = "Flag" - val HigherKinded: N = "HigherKinded" val Ident: N = "Ident" val Import: N = "Import" val Literal: N = "Literal" @@ -645,10 +645,14 @@ object StdNames { def syntheticTypeParamNames(num: Int): List[TypeName] = (0 until num).map(syntheticTypeParamName)(breakOut) - def higherKindedTraitName(n: Int) = HigherKinded ++ n.toString + def higherKindedTraitName(vcs: List[Int]): TypeName = HK_TRAIT_PREFIX ++ vcs.map(varianceSuffix).mkString def higherKindedParamName(n: Int) = HK_PARAM_PREFIX ++ n.toString final val Conforms = encode("<:<") + + def varianceSuffix(v: Int): Char = varianceSuffixes.charAt(v + 1) + + val varianceSuffixes = "NIP" } abstract class JavaNames[N <: Name] extends DefinedNames[N] { diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala index 0abd28a716ab..b61f39ed7f0e 100644 --- a/src/dotty/tools/dotc/core/TypeApplications.scala +++ b/src/dotty/tools/dotc/core/TypeApplications.scala @@ -10,6 +10,7 @@ import util.common._ import Names._ import Flags._ import util.Positions.Position +import config.Printers._ import collection.mutable object TypeApplications { @@ -137,6 +138,8 @@ class TypeApplications(val self: Type) extends AnyVal { tp.underlying.appliedTo(args) case AndType(l, r) => l.appliedTo(args) & r + case tp: PolyType => + tp.instantiate(args) case ErrorType => self } @@ -193,13 +196,32 @@ class TypeApplications(val self: Type) extends AnyVal { NoType } - /** The base type including all type arguments of this type. + /** The base type including all type arguments and applicable refinements + * of this type. Refinements are applicable if they refine a member of + * the parent type which furthermore is not a name-mangled type parameter. * Existential types in arguments are returned as TypeBounds instances. */ - final def baseTypeWithArgs(base: Symbol)(implicit ctx: Context): Type = self.dealias match { - case AndType(tp1, tp2) => tp1.baseTypeWithArgs(base) & tp2.baseTypeWithArgs(base) - case OrType(tp1, tp2) => tp1.baseTypeWithArgs(base) | tp2.baseTypeWithArgs(base) - case _ => self.baseTypeRef(base).appliedTo(baseArgInfos(base)) + final def baseTypeWithArgs(base: Symbol)(implicit ctx: Context): Type = ctx.traceIndented(s"btwa ${self.show} wrt $base", core, show = true) { + def default = self.baseTypeRef(base).appliedTo(baseArgInfos(base)) + self match { + case tp: TypeRef => + tp.info match { + case TypeBounds(_, hi) => hi.baseTypeWithArgs(base) + case _ => default + } + case tp @ RefinedType(parent, name) if !tp.member(name).symbol.is(ExpandedTypeParam) => + val pbase = parent.baseTypeWithArgs(base) + if (pbase.member(name).exists) RefinedType(pbase, name, tp.refinedInfo) + else pbase + case tp: TermRef => + tp.underlying.baseTypeWithArgs(base) + case AndType(tp1, tp2) => + tp1.baseTypeWithArgs(base) & tp2.baseTypeWithArgs(base) + case OrType(tp1, tp2) => + tp1.baseTypeWithArgs(base) | tp2.baseTypeWithArgs(base) + case _ => + default + } } /** Translate a type of the form From[T] to To[T], keep other types as they are. diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index cfb9477c3a11..ce1c1e869cde 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -201,7 +201,11 @@ class TypeComparer(initctx: Context) extends DotClass { def isNonBottomSubType(tp1: Type, tp2: Type): Boolean = !(tp2 isRef NothingClass) && isSubType(tp1, tp2) - def isSubType(tp1: Type, tp2: Type): Boolean = /*>|>*/ ctx.traceIndented(s"isSubType ${tp1.show} <:< ${tp2.show}", subtyping) /*<|<*/ { + private def traceInfo(tp1: Type, tp2: Type) = + s"${tp1.show} <:< ${tp2.show}" + + (if (ctx.settings.verbose.value) s"${tp1.getClass} ${tp2.getClass}" else "") + + def isSubType(tp1: Type, tp2: Type): Boolean = /*>|>*/ ctx.traceIndented(s"isSubType ${traceInfo(tp1, tp2)}", subtyping) /*<|<*/ { if (tp2 eq NoType) false else if (tp1 eq tp2) true else { @@ -408,8 +412,7 @@ class TypeComparer(initctx: Context) extends DotClass { val base = tp1.baseTypeRef(cls2) if (base.exists && (base ne tp1)) return isSubType(base, tp2) if ( cls2 == defn.SingletonClass && tp1.isStable - || cls2 == defn.NotNullClass && tp1.isNotNull - || (defn.hkTraits contains cls2) && isSubTypeHK(tp1, tp2)) return true + || cls2 == defn.NotNullClass && tp1.isNotNull) return true } fourthTry(tp1, tp2) } @@ -426,7 +429,9 @@ class TypeComparer(initctx: Context) extends DotClass { } case _ => tp2 } - def compareRefined: Boolean = tp1.widen match { + def compareRefined: Boolean = + if (defn.hkTraits contains parent2.typeSymbol) isSubTypeHK(tp1, tp2) + else tp1.widen match { case tp1 @ RefinedType(parent1, name1) if nameMatches(name1, name2, tp1, tp2) => // optimized case; all info on tp1.name2 is in refinement tp1.refinedInfo. isSubType(tp1.refinedInfo, tp2.refinedInfo) && { @@ -439,7 +444,7 @@ class TypeComparer(initctx: Context) extends DotClass { case mbr: SingleDenotation => qualifies(mbr) case _ => mbr hasAltWith qualifies } - def hasMatchingMember(name: Name): Boolean = /*>|>*/ ctx.traceIndented(s"hasMatchingMember($name) ${tp1.member(name)}", subtyping) /*<|<*/ ( + def hasMatchingMember(name: Name): Boolean = /*>|>*/ ctx.traceIndented(s"hasMatchingMember($name) ${tp1.member(name).info.show}", subtyping) /*<|<*/ ( memberMatches(tp1 member name) || { // special case for situations like: @@ -467,7 +472,7 @@ class TypeComparer(initctx: Context) extends DotClass { case tp2 @ MethodType(_, formals2) => def compareMethod = tp1 match { case tp1 @ MethodType(_, formals1) => - tp1.signature == tp2.signature && + (tp1.signature sameParams tp2.signature) && (if (Config.newMatch) subsumeParams(formals1, formals2, tp1.isJava, tp2.isJava) else matchingParams(formals1, formals2, tp1.isJava, tp2.isJava)) && tp1.isImplicit == tp2.isImplicit && // needed? @@ -532,7 +537,20 @@ class TypeComparer(initctx: Context) extends DotClass { (tp1.symbol eq NullClass) && tp2.dealias.typeSymbol.isNullableClass } case tp1: SingletonType => - isNewSubType(tp1.underlying.widenExpr, tp2) + isNewSubType(tp1.underlying.widenExpr, tp2) || { + // if tp2 == p.type and p: q.type then try tp1 <:< q.type as a last effort. + tp2 match { + case tp2: TermRef => + tp2.info match { + case tp2i: TermRef => + isSubType(tp1, tp2i) + case _ => + false + } + case _ => + false + } + } case tp1: RefinedType => isNewSubType(tp1.parent, tp2) case AndType(tp11, tp12) => @@ -612,20 +630,33 @@ class TypeComparer(initctx: Context) extends DotClass { * This is the case if `tp1` and `tp2` have the same number * of type parameters, the bounds of tp1's paremeters * are contained in the corresponding bounds of tp2's parameters - * and the variances of correesponding parameters agree. + * and the variances of the parameters agree. + * The variances agree if the supertype parameter is invariant, + * or both parameters have the same variance. + * + * Note: When we get to isSubTypeHK, it might be that tp1 is + * instantiated, or not. If it is instantiated, we compare + * actual argument infos against higher-kinded bounds, + * if it is not instantiated we compare type parameter bounds + * and also compare variances. */ - def isSubTypeHK(tp1: Type, tp2: Type): Boolean = { + def isSubTypeHK(tp1: Type, tp2: Type): Boolean = ctx.traceIndented(s"isSubTypeHK(${tp1.show}, ${tp2.show}", subtyping) { val tparams = tp1.typeParams - val hkArgs = tp2.argInfos - (hkArgs.length == tparams.length) && { - val base = tp1.narrow - (tparams, hkArgs).zipped.forall { (tparam, hkArg) => - isSubType(base.memberInfo(tparam), hkArg.bounds) // TODO: base.memberInfo needed? - } && - (tparams, tp2.typeSymbol.typeParams).zipped.forall { (tparam, tparam2) => - tparam.variance == tparam2.variance - } - } + val argInfos1 = tp1.argInfos + val args1 = + if (argInfos1.nonEmpty) argInfos1 // tp1 is instantiated, use the argument infos + else { // tp1 is uninstantiated, use the parameter bounds + val base = tp1.narrow + tparams.map(base.memberInfo) + } + val hkBounds = tp2.argInfos.map(_.asInstanceOf[TypeBounds]) + val boundsOK = (hkBounds corresponds args1)(_ contains _) + val variancesOK = + argInfos1.nonEmpty || (tparams corresponds tp2.typeSymbol.name.hkVariances) { (tparam, v) => + v == 0 || tparam.variance == v + } + hk.println(s"isSubTypeHK: args1 = $args1, hk-bounds = $hkBounds $boundsOK $variancesOK") + boundsOK && variancesOK } def trySetType(tr: NamedType, bounds: TypeBounds): Boolean = diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 9b5e02186199..7cd66f5ddd5f 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -121,7 +121,11 @@ object Types { * !!! Todo: What about non-final vals that contain abstract types? */ final def isLegalPrefix(implicit ctx: Context): Boolean = - isStable || memberNames(abstractTypeNameFilter).isEmpty + isStable || { + val absTypeNames = memberNames(abstractTypeNameFilter) + if (absTypeNames.nonEmpty) typr.println(s"abstract type members of ${this.showWithUnderlying()}: $absTypeNames") + absTypeNames.isEmpty + } /** Is this type guaranteed not to have `null` as a value? * For the moment this is only true for modules, but it could @@ -621,11 +625,11 @@ object Types { * * to just U */ - def lookupRefined(pre: Type, name: Name)(implicit ctx: Context): Type = pre.stripTypeVar match { + def lookupRefined(name: Name)(implicit ctx: Context): Type = stripTypeVar match { case pre: RefinedType => - if (pre.refinedName ne name) lookupRefined(pre.parent, name) + if (pre.refinedName ne name) pre.parent.lookupRefined(name) else pre.refinedInfo match { - case TypeBounds(lo, hi) if lo eq hi => hi + case TypeBounds(lo, hi) /*if lo eq hi*/ => hi case _ => NoType } case pre: WildcardType => @@ -639,7 +643,7 @@ object Types { case name: TermName => TermRef(this, name) case name: TypeName => - val res = lookupRefined(this, name) + val res = lookupRefined(name) if (res.exists) res else TypeRef(this, name) } @@ -648,7 +652,7 @@ object Types { case name: TermName => TermRef(this, name, denot) case name: TypeName => - val res = lookupRefined(this, name) + val res = lookupRefined(name) if (res.exists) res else TypeRef(this, name, denot) } @@ -656,7 +660,7 @@ object Types { def select(sym: Symbol)(implicit ctx: Context): Type = if (sym.isTerm) TermRef(this, sym.asTerm) else { - val res = lookupRefined(this, sym.name) + val res = lookupRefined(sym.name) if (res.exists) res else TypeRef(this, sym.asType) } @@ -811,6 +815,14 @@ object Types { /** Convert to text */ def toText(printer: Printer): Text = printer.toText(this) + /** Utility method to show the underlying type of a TypeProxy chain together + * with the proxy type itself. + */ + def showWithUnderlying(n: Int = 1)(implicit ctx: Context): String = this match { + case tp: TypeProxy if n > 0 => s"$show with underlying ${tp.underlying.showWithUnderlying(n - 1)}" + case _ => show + } + type VarianceMap = SimpleMap[TypeVar, Integer] /** All occurrences of type vars in this type that satisfy predicate @@ -1102,7 +1114,7 @@ object Types { def derivedSelect(prefix: Type)(implicit ctx: Context): Type = if (prefix eq this.prefix) this else { - val res = lookupRefined(prefix, name) + val res = prefix.lookupRefined(name) if (res.exists) res else newLikeThis(prefix) } @@ -1297,12 +1309,13 @@ object Types { lazy val underlyingTypeParams = parent.safeUnderlyingTypeParams lazy val originalTypeParam = underlyingTypeParams(refinedName.hkParamIndex) - /** drop any co/contra variance in refined info if variance disagrees - * with new type param + /** Use variance of newly instantiated type parameter rather than the old hk argument */ - def adjustedHKRefinedInfo(hkBounds: TypeBounds) = { - if (hkBounds.variance == originalTypeParam.info.bounds.variance) hkBounds - else TypeBounds(hkBounds.lo, hkBounds.hi) + def adjustedHKRefinedInfo(hkBounds: TypeBounds, underlyingTypeParam: TypeSymbol) = hkBounds match { + case tp @ TypeBounds(lo, hi) if lo eq hi => + tp.derivedTypeBounds(lo, hi, underlyingTypeParam.variance) + case _ => + hkBounds } if ((parent eq this.parent) && (refinedName eq this.refinedName) && (refinedInfo eq this.refinedInfo)) @@ -1311,7 +1324,8 @@ object Types { // && { println(s"deriving $refinedName $parent $underlyingTypeParams"); true } && refinedName.hkParamIndex < underlyingTypeParams.length && originalTypeParam.name != refinedName) - derivedRefinedType(parent, originalTypeParam.name, adjustedHKRefinedInfo(refinedInfo.bounds)) + derivedRefinedType(parent, originalTypeParam.name, + adjustedHKRefinedInfo(refinedInfo.bounds, underlyingTypeParams(refinedName.hkParamIndex))) else RefinedType(parent, refinedName, rt => refinedInfo.substThis(this, RefinedThis(rt))) } @@ -1774,7 +1788,7 @@ object Types { // upper bound is not a singleton type, widen the instance. if (fromBelow && isSingleton(inst) && !isSingleton(upperBound)) inst = inst.widen - + inst = inst.simplified // 2. If instance is from below and is a fully-defined union type, yet upper bound @@ -1782,7 +1796,7 @@ object Types { // of all common base types. if (fromBelow && isOrType(inst) && isFullyDefined(inst) && !isOrType(upperBound)) inst = inst.approximateUnion - + instantiateWith(inst) } @@ -1912,7 +1926,10 @@ object Types { if (lo eq tp) this else TypeAlias(tp, variance) - def contains(tp: Type)(implicit ctx: Context) = lo <:< tp && tp <:< hi + def contains(tp: Type)(implicit ctx: Context) = tp match { + case tp: TypeBounds => lo <:< tp.lo && tp.hi <:< hi + case _ => lo <:< tp && tp <:< hi + } def & (that: TypeBounds)(implicit ctx: Context): TypeBounds = { val v = this commonVariance that @@ -2094,6 +2111,8 @@ object Types { zeroParamClass(tp.underlying) case tp: RefinedType => zeroParamClass(tp.underlying) + case tp: TypeBounds => + zeroParamClass(tp.underlying) case tp: TypeVar => zeroParamClass(tp.underlying) case _ => @@ -2283,7 +2302,7 @@ object Types { case tp: TypeRef => if (stopAtStatic && tp.symbol.isStatic) x else { - val tp1 = tp.lookupRefined(tp.prefix, tp.name) + val tp1 = tp.prefix.lookupRefined(tp.name) this(x, if (tp1.exists) tp1 else tp.prefix) } case tp: TermRef => @@ -2405,7 +2424,15 @@ object Types { /** A filter for names of abstract types of a given type */ object abstractTypeNameFilter extends NameFilter { def apply(pre: Type, name: Name)(implicit ctx: Context): Boolean = - name.isTypeName && ((pre member name).symbol is Deferred) + name.isTypeName && { + val mbr = pre.member(name) + (mbr.symbol is Deferred) && { + mbr.info match { + case TypeBounds(lo, hi) => lo ne hi + case _ => false + } + } + } } /** A filter for names of deferred term definitions of a given type */ diff --git a/src/dotty/tools/dotc/core/transform/Erasure.scala b/src/dotty/tools/dotc/core/transform/Erasure.scala index eaeb3c8e75e0..093b59ae8112 100644 --- a/src/dotty/tools/dotc/core/transform/Erasure.scala +++ b/src/dotty/tools/dotc/core/transform/Erasure.scala @@ -126,7 +126,9 @@ object Erasure { sigName(tp1) case OrType(tp1, tp2) => lubClass(tp1, tp2).name - case ErrorType | WildcardType => + case tp: WildcardType => + tpnme.WILDCARD + case ErrorType => tpnme.WILDCARD } diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala index aea019bed612..7bc7d55161c4 100644 --- a/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/src/dotty/tools/dotc/parsing/Parsers.scala @@ -2071,6 +2071,7 @@ object Parsers { topstats() match { case List(stat @ PackageDef(_, _)) => stat + case Nil => EmptyTree // without this case we'd get package defs without positions case stats => PackageDef(Ident(nme.EMPTY_PACKAGE), stats) } } diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index 4d26532d656e..46a6ebf66a16 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -785,9 +785,13 @@ trait Applications extends Compatibility { self: Typer => }} /** Drop any implicit parameter section */ - def stripImplicit(tp: Type) = tp match { - case mt: ImplicitMethodType if !mt.isDependent => mt.resultType // todo: make sure implicit method types are not dependent - case _ => tp + def stripImplicit(tp: Type): Type = tp match { + case mt: ImplicitMethodType if !mt.isDependent => + mt.resultType // todo: make sure implicit method types are not dependent + case pt: PolyType => + pt.derivedPolyType(pt.paramNames, pt.paramBounds, stripImplicit(pt.resultType)) + case _ => + tp } val owner1 = alt1.symbol.owner @@ -800,6 +804,8 @@ trait Applications extends Compatibility { self: Typer => def winsOwner2 = isDerived(owner2, owner1) def winsType2 = isAsSpecific(alt2, tp2, alt1, tp1) + implicits.println(i"isAsGood($alt1, $alt2)? $tp1 $tp2 $winsOwner1 $winsType1 $winsOwner2 $winsType2") + // Assume the following probabilities: // // P(winsOwnerX) = 2/3 diff --git a/src/dotty/tools/dotc/typer/EtaExpansion.scala b/src/dotty/tools/dotc/typer/EtaExpansion.scala index 46a1d35832e0..099dd943a608 100644 --- a/src/dotty/tools/dotc/typer/EtaExpansion.scala +++ b/src/dotty/tools/dotc/typer/EtaExpansion.scala @@ -95,25 +95,35 @@ object EtaExpansion { /** Eta-expanding a tree means converting a method reference to a function value. * @param tree The tree to expand - * @param paramNames The names of the parameters to use in the expansion - * Let `paramNames` be x1, ..., xn + * @param mt The type of the method reference + * @param xarity The arity of the expected function type * and assume the lifted application of `tree` (@see liftApp) is * * { val xs = es; expr } * - * Then the eta-expansion is + * If xarity matches the number of parameters in `mt`, the eta-expansion is * - * { val xs = es; (x1, ..., xn) => expr(xx1, ..., xn) } + * { val xs = es; (x1, ..., xn) => expr(x1, ..., xn) } * - * This is an untyped tree, with `es` and `expr` as typed splices. + * Note that the function value's parameters are untyped, hence the type will + * be supplied by the environment (or if missing be supplied by the target + * method as a fallback). On the other hand, if `xarity` is different from + * the number of parameters in `mt`, then we cannot propagate parameter types + * from the expected type, and we fallback to using the method's original + * parameter types instead. + * + * In either case, the result is an untyped tree, with `es` and `expr` as typed splices. */ - def etaExpand(tree: Tree, paramNames: List[TermName])(implicit ctx: Context): untpd.Tree = { + def etaExpand(tree: Tree, mt: MethodType, xarity: Int)(implicit ctx: Context): untpd.Tree = { import untpd._ val defs = new mutable.ListBuffer[tpd.Tree] val lifted: Tree = TypedSplice(liftApp(defs, tree)) - val params = paramNames map (name => - ValDef(Modifiers(Synthetic | Param), name, TypeTree(), EmptyTree).withPos(tree.pos)) - val ids = paramNames map (name => + val paramTypes: List[Tree] = + if (mt.paramTypes.length == xarity) mt.paramTypes map (_ => TypeTree()) + else mt.paramTypes map TypeTree + val params = (mt.paramNames, paramTypes).zipped.map((name, tpe) => + ValDef(Modifiers(Synthetic | Param), name, TypeTree(tpe), EmptyTree).withPos(tree.pos)) + val ids = mt.paramNames map (name => Ident(name).withPos(tree.pos)) val body = Apply(lifted, ids) val fn = untpd.Function(params, body) diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala index b939c1b0d8f5..fe1c938c9b44 100644 --- a/src/dotty/tools/dotc/typer/Implicits.scala +++ b/src/dotty/tools/dotc/typer/Implicits.scala @@ -65,7 +65,7 @@ object Implicits { case tpw => //if (ctx.typer.isApplicable(tp, argType :: Nil, resultType)) // println(i"??? $tp is applicable to $this / typeSymbol = ${tpw.typeSymbol}") - true + !tpw.derivesFrom(defn.FunctionClass(1)) } def discardForValueType(tpw: Type): Boolean = tpw match { @@ -419,11 +419,6 @@ trait Implicits { self: Typer => /** An implicit search; parameters as in `inferImplicit` */ class ImplicitSearch(protected val pt: Type, protected val argument: Tree, pos: Position)(implicit ctx: Context) { - pt match { - case pt: TypeVar => assert(pt.isInstantiated) //!!! DEBUG - case _ => - } - private def nestedContext = ctx.fresh.withNewMode(ctx.mode &~ Mode.ImplicitsEnabled) private def implicitProto(resultType: Type, f: Type => Type) = diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 7885e85acdf2..361de802c742 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -549,6 +549,8 @@ class Namer { typer: Typer => else NoType } val iResType = iInstInfo.finalResultType.asSeenFrom(site, cls) + if (iResType.exists) + typr.println(s"using inherited type; raw: $iRawInfo, inst: $iInstInfo, inherited: $iResType") tp & iResType } } diff --git a/src/dotty/tools/dotc/typer/ProtoTypes.scala b/src/dotty/tools/dotc/typer/ProtoTypes.scala index 74be3f4cd1c6..16fcc9db7cd1 100644 --- a/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -79,7 +79,9 @@ object ProtoTypes { override def isMatchedBy(tp1: Type)(implicit ctx: Context) = { name == nme.WILDCARD || { val mbr = tp1.member(name) - def qualifies(m: SingleDenotation) = compat.normalizedCompatible(m.info, memberProto) + def qualifies(m: SingleDenotation) = + memberProto.isRef(defn.UnitClass) || + compat.normalizedCompatible(m.info, memberProto) mbr match { // hasAltWith inlined for performance case mbr: SingleDenotation => mbr.exists && qualifies(mbr) case _ => mbr hasAltWith qualifies diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 67e5c59024fe..7c301a7f1ab7 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -209,7 +209,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit if (qualifies(defDenot)) { val curOwner = ctx.owner val found = - if (isSelfDenot(defDenot)) curOwner.thisType + if (isSelfDenot(defDenot)) curOwner.enclosingClass.thisType else curOwner.thisType.select(name, defDenot) if (!(curOwner is Package) || (defDenot.symbol is Package) || isDefinedInCurrentUnit(defDenot)) return checkNewOrShadowed(found, definition) // no need to go further out, we found highest prec entry @@ -496,14 +496,15 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit errorType(s"missing parameter type for parameter ${param.name}$ofFun, expected = ${pt.show}", param.pos) } - if (protoFormals.length != params.length) - ctx.error(s"wrong number of parameters, expected: ${protoFormals.length}", tree.pos) + def protoFormal(i: Int): Type = + if (protoFormals.length == params.length) protoFormals(i) + else errorType(s"wrong number of parameters, expected: ${protoFormals.length}", tree.pos) val inferredParams: List[untpd.ValDef] = - for ((param, formal) <- params zip protoFormals) yield + for ((param, i) <- params.zipWithIndex) yield if (!param.tpt.isEmpty) param else { - val paramTpt = untpd.TypeTree(inferredParamType(param, formal)) + val paramTpt = untpd.TypeTree(inferredParamType(param, protoFormal(i))) cpy.ValDef(param, param.mods, param.name, paramTpt, param.rhs) } @@ -1135,7 +1136,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit else if (pt eq AnyFunctionProto) wtp.paramTypes.length else -1 if (arity >= 0 && !tree.symbol.isConstructor) - typed(etaExpand(tree, wtp.paramNames take arity), pt) + typed(etaExpand(tree, wtp, arity), pt) else if (wtp.paramTypes.isEmpty) adaptInterpolated(tpd.Apply(tree, Nil), pt) else diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index 1ddd0a578d75..ed6f3b5d9166 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -47,7 +47,7 @@ class tests extends CompilerTest { @Test def pos_approximateUnion = compileFile(posDir, "approximateUnion", twice) */ @Test def pos_all = compileFiles(posDir, twice) - @Test def pos_new = compileFiles(newDir, "-Xprompt" :: Nil) + @Test def new_all = compileFiles(newDir, twice) @Test def neg_blockescapes() = compileFile(negDir, "blockescapesNeg", xerrors = 1) @Test def neg_typedapply() = compileFile(negDir, "typedapply", xerrors = 4) @@ -57,11 +57,14 @@ class tests extends CompilerTest { @Test def neg_privates() = compileFile(negDir, "privates", xerrors = 2) @Test def neg_rootImports = compileFile(negDir, "rootImplicits", xerrors = 2) @Test def neg_templateParents() = compileFile(negDir, "templateParents", xerrors = 3) - @Test def neg_i39 = compileFile(negDir, "i39", xerrors = 1) - @Test def neg_i50_volatile = compileFile(negDir, "i50-volatile", xerrors = 4) - @Test def neg_companions = compileFile(negDir, "companions", xerrors = 1) @Test def neg_autoTupling = compileFile(posDir, "autoTuplingTest", "-language:noAutoTupling" :: Nil, xerrors = 3) @Test def neg_autoTupling2 = compileFile(negDir, "autoTuplingTest", xerrors = 3) + @Test def neg_companions = compileFile(negDir, "companions", xerrors = 1) + @Test def neg_i39 = compileFile(negDir, "i39", xerrors = 1) + @Test def neg_i50_volatile = compileFile(negDir, "i50-volatile", xerrors = 4) + @Test def neg_t0273_doubledefs = compileFile(negDir, "t0273", xerrors = 1) + @Test def neg_t0654_polyalias = compileFile(negDir, "t0654", xerrors = 2) + @Test def neg_t1192_legalPrefix = compileFile(negDir, "t1192", xerrors = 1) @Test def dotc = compileDir(dotcDir + "tools/dotc", twice) @Test def dotc_ast = compileDir(dotcDir + "tools/dotc/ast", twice) diff --git a/tests/untried/pos/t0288/Foo.scala b/tests/disabled/java-interop/pos/t0288/Foo.scala similarity index 100% rename from tests/untried/pos/t0288/Foo.scala rename to tests/disabled/java-interop/pos/t0288/Foo.scala diff --git a/tests/untried/pos/t0288/Outer.java b/tests/disabled/java-interop/pos/t0288/Outer.java similarity index 100% rename from tests/untried/pos/t0288/Outer.java rename to tests/disabled/java-interop/pos/t0288/Outer.java diff --git a/tests/untried/pos/t0695/JavaClass.java b/tests/disabled/java-interop/pos/t0695/JavaClass.java similarity index 100% rename from tests/untried/pos/t0695/JavaClass.java rename to tests/disabled/java-interop/pos/t0695/JavaClass.java diff --git a/tests/untried/pos/t0695/Test.scala b/tests/disabled/java-interop/pos/t0695/Test.scala similarity index 100% rename from tests/untried/pos/t0695/Test.scala rename to tests/disabled/java-interop/pos/t0695/Test.scala diff --git a/tests/untried/pos/t1101/J.java b/tests/disabled/java-interop/pos/t1101/J.java similarity index 100% rename from tests/untried/pos/t1101/J.java rename to tests/disabled/java-interop/pos/t1101/J.java diff --git a/tests/untried/pos/t1101/S.scala b/tests/disabled/java-interop/pos/t1101/S.scala similarity index 100% rename from tests/untried/pos/t1101/S.scala rename to tests/disabled/java-interop/pos/t1101/S.scala diff --git a/tests/untried/pos/t1102/J.java b/tests/disabled/java-interop/pos/t1102/J.java similarity index 100% rename from tests/untried/pos/t1102/J.java rename to tests/disabled/java-interop/pos/t1102/J.java diff --git a/tests/untried/pos/t1102/S.scala b/tests/disabled/java-interop/pos/t1102/S.scala similarity index 100% rename from tests/untried/pos/t1102/S.scala rename to tests/disabled/java-interop/pos/t1102/S.scala diff --git a/tests/untried/pos/t1150/J.java b/tests/disabled/java-interop/pos/t1150/J.java similarity index 100% rename from tests/untried/pos/t1150/J.java rename to tests/disabled/java-interop/pos/t1150/J.java diff --git a/tests/untried/pos/t1150/S.scala b/tests/disabled/java-interop/pos/t1150/S.scala similarity index 100% rename from tests/untried/pos/t1150/S.scala rename to tests/disabled/java-interop/pos/t1150/S.scala diff --git a/tests/untried/pos/t1152/J.java b/tests/disabled/java-interop/pos/t1152/J.java similarity index 100% rename from tests/untried/pos/t1152/J.java rename to tests/disabled/java-interop/pos/t1152/J.java diff --git a/tests/untried/pos/t1152/S.scala b/tests/disabled/java-interop/pos/t1152/S.scala similarity index 100% rename from tests/untried/pos/t1152/S.scala rename to tests/disabled/java-interop/pos/t1152/S.scala diff --git a/tests/untried/pos/t1176/J.java b/tests/disabled/java-interop/pos/t1176/J.java similarity index 100% rename from tests/untried/pos/t1176/J.java rename to tests/disabled/java-interop/pos/t1176/J.java diff --git a/tests/untried/pos/t1176/S.scala b/tests/disabled/java-interop/pos/t1176/S.scala similarity index 100% rename from tests/untried/pos/t1176/S.scala rename to tests/disabled/java-interop/pos/t1176/S.scala diff --git a/tests/untried/pos/t1186/t1186.java b/tests/disabled/java-interop/pos/t1186/t1186.java similarity index 100% rename from tests/untried/pos/t1186/t1186.java rename to tests/disabled/java-interop/pos/t1186/t1186.java diff --git a/tests/untried/pos/t1196/J.java b/tests/disabled/java-interop/pos/t1196/J.java similarity index 100% rename from tests/untried/pos/t1196/J.java rename to tests/disabled/java-interop/pos/t1196/J.java diff --git a/tests/untried/pos/t1196/S.scala b/tests/disabled/java-interop/pos/t1196/S.scala similarity index 100% rename from tests/untried/pos/t1196/S.scala rename to tests/disabled/java-interop/pos/t1196/S.scala diff --git a/tests/untried/pos/t1197/J.java b/tests/disabled/java-interop/pos/t1197/J.java similarity index 100% rename from tests/untried/pos/t1197/J.java rename to tests/disabled/java-interop/pos/t1197/J.java diff --git a/tests/untried/pos/t1197/S.scala b/tests/disabled/java-interop/pos/t1197/S.scala similarity index 100% rename from tests/untried/pos/t1197/S.scala rename to tests/disabled/java-interop/pos/t1197/S.scala diff --git a/tests/untried/pos/t1203b/J.java b/tests/disabled/java-interop/pos/t1203b/J.java similarity index 100% rename from tests/untried/pos/t1203b/J.java rename to tests/disabled/java-interop/pos/t1203b/J.java diff --git a/tests/untried/pos/t1203b/S.scala b/tests/disabled/java-interop/pos/t1203b/S.scala similarity index 100% rename from tests/untried/pos/t1203b/S.scala rename to tests/disabled/java-interop/pos/t1203b/S.scala diff --git a/tests/untried/pos/t1230/J.java b/tests/disabled/java-interop/pos/t1230/J.java similarity index 100% rename from tests/untried/pos/t1230/J.java rename to tests/disabled/java-interop/pos/t1230/J.java diff --git a/tests/untried/pos/t1230/S.scala b/tests/disabled/java-interop/pos/t1230/S.scala similarity index 100% rename from tests/untried/pos/t1230/S.scala rename to tests/disabled/java-interop/pos/t1230/S.scala diff --git a/tests/untried/pos/t1231/J.java b/tests/disabled/java-interop/pos/t1231/J.java similarity index 100% rename from tests/untried/pos/t1231/J.java rename to tests/disabled/java-interop/pos/t1231/J.java diff --git a/tests/untried/pos/t1231/S.scala b/tests/disabled/java-interop/pos/t1231/S.scala similarity index 100% rename from tests/untried/pos/t1231/S.scala rename to tests/disabled/java-interop/pos/t1231/S.scala diff --git a/tests/untried/pos/t1232/J.java b/tests/disabled/java-interop/pos/t1232/J.java similarity index 100% rename from tests/untried/pos/t1232/J.java rename to tests/disabled/java-interop/pos/t1232/J.java diff --git a/tests/untried/pos/t1232/J2.java b/tests/disabled/java-interop/pos/t1232/J2.java similarity index 100% rename from tests/untried/pos/t1232/J2.java rename to tests/disabled/java-interop/pos/t1232/J2.java diff --git a/tests/untried/pos/t1232/S.scala b/tests/disabled/java-interop/pos/t1232/S.scala similarity index 100% rename from tests/untried/pos/t1232/S.scala rename to tests/disabled/java-interop/pos/t1232/S.scala diff --git a/tests/untried/pos/t1235/Test.java b/tests/disabled/java-interop/pos/t1235/Test.java similarity index 100% rename from tests/untried/pos/t1235/Test.java rename to tests/disabled/java-interop/pos/t1235/Test.java diff --git a/tests/untried/pos/t1254/t1254.java b/tests/disabled/java-interop/pos/t1254/t1254.java similarity index 100% rename from tests/untried/pos/t1254/t1254.java rename to tests/disabled/java-interop/pos/t1254/t1254.java diff --git a/tests/untried/pos/t1263/Test.java b/tests/disabled/java-interop/pos/t1263/Test.java similarity index 100% rename from tests/untried/pos/t1263/Test.java rename to tests/disabled/java-interop/pos/t1263/Test.java diff --git a/tests/untried/pos/t1263/test.scala b/tests/disabled/java-interop/pos/t1263/test.scala similarity index 100% rename from tests/untried/pos/t1263/test.scala rename to tests/disabled/java-interop/pos/t1263/test.scala diff --git a/tests/untried/pos/t0273.scala b/tests/neg/t0273.scala similarity index 65% rename from tests/untried/pos/t0273.scala rename to tests/neg/t0273.scala index ac02b8c15a6e..10f4268288fb 100644 --- a/tests/untried/pos/t0273.scala +++ b/tests/neg/t0273.scala @@ -3,4 +3,5 @@ class A object Test { def a = () => () def a[T] = (p:A) => () +def main(args: Array[String]) = () } diff --git a/tests/neg/t0654.scala b/tests/neg/t0654.scala new file mode 100644 index 000000000000..52dbbb014c03 --- /dev/null +++ b/tests/neg/t0654.scala @@ -0,0 +1,5 @@ +object Test { + class Foo[T] + type C[T] = Foo[_ <: T] // error: parameter type T of type alias does not appear as type argument of the aliased class Foo + val a: C[AnyRef] = new Foo[AnyRef] // follow-on error: wrong number of type arguments for Test.C, should be 0 +} diff --git a/tests/neg/t1292.scala b/tests/neg/t1292.scala new file mode 100644 index 000000000000..69e680320909 --- /dev/null +++ b/tests/neg/t1292.scala @@ -0,0 +1,35 @@ +trait Foo[T <: Foo[T, Enum], Enum <: Enumeration] { + type StV = Enum#Value + type Meta = MegaFoo[T, Enum] + + type Slog <: Enumeration + + def getSingleton: Meta +} + +trait MegaFoo[T <: Foo[T, Enum], Enum <: Enumeration] extends Foo[T, Enum] { + def doSomething(what: T, misc: StV, dog: Meta#Event) = None + // error: Meta is not a valid prefix for '#'. + // The error is correct. Meta is not stable, and it has an abstract type member Slog + abstract class Event + object Event + + def stateEnumeration: Slog + def se2: Enum +} + +object E extends Enumeration { + val A = Value + val B = Value +} + +class RFoo extends Foo[RFoo, E.type] { + def getSingleton = MegaRFoo + + type Slog = E.type +} + +object MegaRFoo extends RFoo with MegaFoo[RFoo, E.type] { + def stateEnumeration = E + def se2 = E +} diff --git a/tests/untried/pos/t1071.scala b/tests/pending/pos/t1071.scala similarity index 50% rename from tests/untried/pos/t1071.scala rename to tests/pending/pos/t1071.scala index 59149a021b01..b241cd648563 100644 --- a/tests/untried/pos/t1071.scala +++ b/tests/pending/pos/t1071.scala @@ -15,3 +15,5 @@ object Test { c.a // error } +// to fix this we'd need to check accessibility in the isMatchedBy of a SelectionProto, +// so that we can insert an implicit if this does not work. Need to check performance impact of this. diff --git a/tests/pending/pos/t1208.scala b/tests/pending/pos/t1208.scala new file mode 100644 index 000000000000..7b14aadca367 --- /dev/null +++ b/tests/pending/pos/t1208.scala @@ -0,0 +1,7 @@ +object Test { + object Foo + val f: Option[Foo.type] = Some(Foo) +} + +// unsupported with current typing rules. +// on the other hand, we need a way to refer to a module class. diff --git a/tests/pos/collections.scala b/tests/pos/collections.scala index cd84f03d83c1..535e4b542143 100644 --- a/tests/pos/collections.scala +++ b/tests/pos/collections.scala @@ -1,10 +1,10 @@ import scala.collection.generic.CanBuildFrom object collections { - + val arr = Array("a", "b") val aa = arr ++ arr - + List(1, 2, 3) map (x => 2) val s = Set(1, 2, 3) @@ -18,16 +18,19 @@ object collections { val ints3: List[Int] = ints2 val f = (x: Int) => x + 1 val ints4: List[Int] = List(1, 2, 3, 5) - + val ys = ints3 map (x => x + 1) val zs = ys filter (y => y != 0) - + val chrs = "abc" - + def do2(x: Int, y: Char) = () - + chrs foreach println - + (ints2, chrs).zipped foreach do2 -} \ No newline at end of file + val xs = List(List(1), List(2), List(3)).iterator + println(xs.flatten) + +} diff --git a/tests/pos/ostermann.scala b/tests/pos/ostermann.scala new file mode 100644 index 000000000000..f3acafc727a9 --- /dev/null +++ b/tests/pos/ostermann.scala @@ -0,0 +1,3 @@ +trait A { def foo(a: A) : Unit } + +trait C extends A { override def foo(a: A with Any) : Unit } diff --git a/tests/pos/overloaded.scala b/tests/pos/overloaded.scala index ebc1501d8580..a26b9b859a8f 100644 --- a/tests/pos/overloaded.scala +++ b/tests/pos/overloaded.scala @@ -2,23 +2,23 @@ object overloaded { def f(x: String): String = x def f[T >: Null](x: T): Int = 1 - + val x1 = f("abc") val x2 = f(new Integer(1)) val x3 = f(null) - + val x4: String => String = f val x5: String => Any = f val x6: Any = f _ - + def g(): Int = 1 def g(x: Int): Int = 2 - + val y1: Int => Int = g - val y2: Any = g _ - + val y2: Any = g _ + println(g) - + val xs = List("a", "b") xs.mkString } diff --git a/tests/untried/pos/t0123.scala b/tests/pos/t0123.scala similarity index 100% rename from tests/untried/pos/t0123.scala rename to tests/pos/t0123.scala diff --git a/tests/untried/pos/t0154.scala b/tests/pos/t0154.scala similarity index 100% rename from tests/untried/pos/t0154.scala rename to tests/pos/t0154.scala diff --git a/tests/untried/pos/t0165.scala b/tests/pos/t0165.scala similarity index 100% rename from tests/untried/pos/t0165.scala rename to tests/pos/t0165.scala diff --git a/tests/untried/pos/t0204.scala b/tests/pos/t0204.scala similarity index 100% rename from tests/untried/pos/t0204.scala rename to tests/pos/t0204.scala diff --git a/tests/untried/pos/t0227.scala b/tests/pos/t0227.scala similarity index 100% rename from tests/untried/pos/t0227.scala rename to tests/pos/t0227.scala diff --git a/tests/untried/pos/t0231.scala b/tests/pos/t0231.scala similarity index 100% rename from tests/untried/pos/t0231.scala rename to tests/pos/t0231.scala diff --git a/tests/untried/pos/t0301.scala b/tests/pos/t0301.scala similarity index 100% rename from tests/untried/pos/t0301.scala rename to tests/pos/t0301.scala diff --git a/tests/untried/pos/t0304.scala b/tests/pos/t0304.scala similarity index 100% rename from tests/untried/pos/t0304.scala rename to tests/pos/t0304.scala diff --git a/tests/untried/pos/t0305.scala b/tests/pos/t0305.scala similarity index 100% rename from tests/untried/pos/t0305.scala rename to tests/pos/t0305.scala diff --git a/tests/untried/pos/t0438.scala b/tests/pos/t0438.scala similarity index 85% rename from tests/untried/pos/t0438.scala rename to tests/pos/t0438.scala index dd1e7f9a9f9b..1615e3da7074 100644 --- a/tests/untried/pos/t0438.scala +++ b/tests/pos/t0438.scala @@ -5,7 +5,7 @@ class Foo { def foo(f: ((Int, Int)) => Int) = f def bar(x: Int, y: Int) = x + y - foo({ (x: Int, y: Int) => x + y }) // works + foo(((x: Int, y: Int) => x + y)) // works foo(pair2fun2(bar _)) // works foo(bar _) // error foo(bar) // same error diff --git a/tests/untried/pos/t0453.scala b/tests/pos/t0453.scala similarity index 100% rename from tests/untried/pos/t0453.scala rename to tests/pos/t0453.scala diff --git a/tests/untried/pos/t0504.scala b/tests/pos/t0504.scala similarity index 100% rename from tests/untried/pos/t0504.scala rename to tests/pos/t0504.scala diff --git a/tests/untried/pos/t0586.scala b/tests/pos/t0586.scala similarity index 100% rename from tests/untried/pos/t0586.scala rename to tests/pos/t0586.scala diff --git a/tests/untried/pos/t0591.scala b/tests/pos/t0591.scala similarity index 79% rename from tests/untried/pos/t0591.scala rename to tests/pos/t0591.scala index 6cb5e29b48dc..0a39cab1bfeb 100644 --- a/tests/untried/pos/t0591.scala +++ b/tests/pos/t0591.scala @@ -1,5 +1,5 @@ object Test { - def implicitly[T](implicit t : T) = t + def implicitly[T](implicit t : T): T = t implicit def perhaps[T](implicit t : T) : Option[T] = Some(t) implicit val hello: String = "Hello" implicitly[String] diff --git a/tests/untried/pos/t0599.scala b/tests/pos/t0599.scala similarity index 100% rename from tests/untried/pos/t0599.scala rename to tests/pos/t0599.scala diff --git a/tests/untried/pos/t0612/C.scala b/tests/pos/t0612/C.scala similarity index 100% rename from tests/untried/pos/t0612/C.scala rename to tests/pos/t0612/C.scala diff --git a/tests/untried/pos/t0612/Ob.scala b/tests/pos/t0612/Ob.scala similarity index 100% rename from tests/untried/pos/t0612/Ob.scala rename to tests/pos/t0612/Ob.scala diff --git a/tests/untried/pos/t0625.scala b/tests/pos/t0625.scala similarity index 100% rename from tests/untried/pos/t0625.scala rename to tests/pos/t0625.scala diff --git a/tests/untried/pos/t0644.scala b/tests/pos/t0644.scala similarity index 100% rename from tests/untried/pos/t0644.scala rename to tests/pos/t0644.scala diff --git a/tests/untried/pos/t0674.scala b/tests/pos/t0674.scala similarity index 100% rename from tests/untried/pos/t0674.scala rename to tests/pos/t0674.scala diff --git a/tests/untried/pos/t0710.scala b/tests/pos/t0710.scala similarity index 100% rename from tests/untried/pos/t0710.scala rename to tests/pos/t0710.scala diff --git a/tests/untried/pos/t0770.scala b/tests/pos/t0770.scala similarity index 100% rename from tests/untried/pos/t0770.scala rename to tests/pos/t0770.scala diff --git a/tests/untried/pos/t0774/deathname.scala b/tests/pos/t0774/deathname.scala similarity index 100% rename from tests/untried/pos/t0774/deathname.scala rename to tests/pos/t0774/deathname.scala diff --git a/tests/untried/pos/t0774/unrelated.scala b/tests/pos/t0774/unrelated.scala similarity index 100% rename from tests/untried/pos/t0774/unrelated.scala rename to tests/pos/t0774/unrelated.scala diff --git a/tests/untried/pos/t0786.scala b/tests/pos/t0786.scala similarity index 67% rename from tests/untried/pos/t0786.scala rename to tests/pos/t0786.scala index b347b0bc5403..b320de0ed6c3 100644 --- a/tests/untried/pos/t0786.scala +++ b/tests/pos/t0786.scala @@ -7,15 +7,15 @@ object ImplicitProblem { def eval: Int } - implicit def toRep0(n: Int): ImplicitProblem.Rep[Int] = new Rep[Int] { + implicit def toRep0(n: Int): Rep[Int] = new Rep[Int] { def eval = 0 } - implicit def toRepN[T](n: M[T])(implicit f: T => Rep[T]): ImplicitProblem.Rep[ImplicitProblem.M[T]] = new Rep[M[T]] { + implicit def toRepN[T](n: M[T])(implicit f: T => Rep[T]): Rep[M[T]] = new Rep[M[T]] { def eval = f(nullval[T]).eval + 1 } - def depth[T <% Rep[T]](n: T) = n.eval + def depth[T](n: T)(implicit ev: T => Rep[T]) = n.eval def main(args: Array[String]): Unit = { println(depth(nullval[M[Int]])) // (1) this works diff --git a/tests/untried/pos/t0851.scala b/tests/pos/t0851.scala similarity index 78% rename from tests/untried/pos/t0851.scala rename to tests/pos/t0851.scala index fcfdba51eba5..fdc504af75c5 100644 --- a/tests/untried/pos/t0851.scala +++ b/tests/pos/t0851.scala @@ -5,7 +5,7 @@ object test1 { def apply(t : T) = (s:T2) => f(t,s) def apply(p : (T,T2)) = f(p._1,p._2) } - implicit def g[T](f : (T,String) => String): test.test1.Foo[T,String] = Foo(f) + implicit def g[T](f : (T,String) => String): Foo[T, String] = Foo(f) def main(args : Array[String]) : Unit = { val f = (x:Int,s:String) => s + x println(f(1)) diff --git a/tests/untried/pos/t0872.scala b/tests/pos/t0872.scala similarity index 100% rename from tests/untried/pos/t0872.scala rename to tests/pos/t0872.scala diff --git a/tests/untried/pos/t0904.scala b/tests/pos/t0904.scala similarity index 100% rename from tests/untried/pos/t0904.scala rename to tests/pos/t0904.scala diff --git a/tests/pos/t0905.scala b/tests/pos/t0905.scala new file mode 100644 index 000000000000..3800c6e0ba10 --- /dev/null +++ b/tests/pos/t0905.scala @@ -0,0 +1,6 @@ +object Test { + trait A[T] + def f(implicit p: A[_]) = null + implicit val x: A[_] = null + println(f) +} diff --git a/tests/untried/pos/t1000.scala b/tests/pos/t1000.scala similarity index 100% rename from tests/untried/pos/t1000.scala rename to tests/pos/t1000.scala diff --git a/tests/untried/pos/t1001.scala b/tests/pos/t1001.scala similarity index 100% rename from tests/untried/pos/t1001.scala rename to tests/pos/t1001.scala diff --git a/tests/untried/pos/t1006.scala b/tests/pos/t1006.scala similarity index 100% rename from tests/untried/pos/t1006.scala rename to tests/pos/t1006.scala diff --git a/tests/untried/pos/t1014.scala b/tests/pos/t1014.scala similarity index 100% rename from tests/untried/pos/t1014.scala rename to tests/pos/t1014.scala diff --git a/tests/untried/pos/t1027.scala b/tests/pos/t1027.scala similarity index 100% rename from tests/untried/pos/t1027.scala rename to tests/pos/t1027.scala diff --git a/tests/untried/pos/t1029/Test_1.scala b/tests/pos/t1029/Test_1.scala similarity index 100% rename from tests/untried/pos/t1029/Test_1.scala rename to tests/pos/t1029/Test_1.scala diff --git a/tests/untried/pos/t1029/Test_2.scala b/tests/pos/t1029/Test_2.scala similarity index 100% rename from tests/untried/pos/t1029/Test_2.scala rename to tests/pos/t1029/Test_2.scala diff --git a/tests/untried/pos/t1034.scala b/tests/pos/t1034.scala similarity index 100% rename from tests/untried/pos/t1034.scala rename to tests/pos/t1034.scala diff --git a/tests/untried/pos/t1035.scala b/tests/pos/t1035.scala similarity index 88% rename from tests/untried/pos/t1035.scala rename to tests/pos/t1035.scala index e0a9379c7ed9..ef81cb0d9fa7 100644 --- a/tests/untried/pos/t1035.scala +++ b/tests/pos/t1035.scala @@ -6,7 +6,7 @@ class A { var name:String = _ def getName() = name - def this(name:String, age:Int){this();this.name=name} + def this(name:String, age:Int) = {this(); this.name = name} } diff --git a/tests/pos/t1048.scala b/tests/pos/t1048.scala new file mode 100644 index 000000000000..b8694b38e694 --- /dev/null +++ b/tests/pos/t1048.scala @@ -0,0 +1,14 @@ +trait T[U] { + def x: T[_ <: U] +} + +object T { + def unapply[U](t: T[U]): Option[T[_ <: U]] = Some(t.x) +} + +object Test { + def f[W](t: T[W]) = t match { + case T(T(_)) => () + } +} + diff --git a/tests/untried/pos/t1049.scala b/tests/pos/t1049.scala similarity index 100% rename from tests/untried/pos/t1049.scala rename to tests/pos/t1049.scala diff --git a/tests/untried/pos/t1050.scala b/tests/pos/t1050.scala similarity index 100% rename from tests/untried/pos/t1050.scala rename to tests/pos/t1050.scala diff --git a/tests/untried/pos/t1053.scala b/tests/pos/t1053.scala similarity index 100% rename from tests/untried/pos/t1053.scala rename to tests/pos/t1053.scala diff --git a/tests/untried/pos/t1056.scala b/tests/pos/t1056.scala similarity index 100% rename from tests/untried/pos/t1056.scala rename to tests/pos/t1056.scala diff --git a/tests/untried/pos/t1070.scala b/tests/pos/t1070.scala similarity index 100% rename from tests/untried/pos/t1070.scala rename to tests/pos/t1070.scala diff --git a/tests/untried/pos/t1075.scala b/tests/pos/t1075.scala similarity index 100% rename from tests/untried/pos/t1075.scala rename to tests/pos/t1075.scala diff --git a/tests/untried/pos/t1085.scala b/tests/pos/t1085.scala similarity index 100% rename from tests/untried/pos/t1085.scala rename to tests/pos/t1085.scala diff --git a/tests/untried/pos/t1090.scala b/tests/pos/t1090.scala similarity index 100% rename from tests/untried/pos/t1090.scala rename to tests/pos/t1090.scala diff --git a/tests/untried/pos/t1107a.scala b/tests/pos/t1107a.scala similarity index 100% rename from tests/untried/pos/t1107a.scala rename to tests/pos/t1107a.scala diff --git a/tests/untried/pos/t1107b/O.scala b/tests/pos/t1107b/O.scala similarity index 100% rename from tests/untried/pos/t1107b/O.scala rename to tests/pos/t1107b/O.scala diff --git a/tests/untried/pos/t1107b/T.scala b/tests/pos/t1107b/T.scala similarity index 100% rename from tests/untried/pos/t1107b/T.scala rename to tests/pos/t1107b/T.scala diff --git a/tests/untried/pos/t1119.scala b/tests/pos/t1119.scala similarity index 100% rename from tests/untried/pos/t1119.scala rename to tests/pos/t1119.scala diff --git a/tests/untried/pos/t1123.scala b/tests/pos/t1123.scala similarity index 73% rename from tests/untried/pos/t1123.scala rename to tests/pos/t1123.scala index 3812fa3eb35c..e3a89c14a404 100644 --- a/tests/untried/pos/t1123.scala +++ b/tests/pos/t1123.scala @@ -7,5 +7,5 @@ object Test { } def f = extraListener.h } - def main(args : Array[String]) : Unit = (new Editor).f + def main(args : Array[String]): Unit = (new Editor).f } diff --git a/tests/untried/pos/t112606A.scala b/tests/pos/t112606A.scala similarity index 100% rename from tests/untried/pos/t112606A.scala rename to tests/pos/t112606A.scala diff --git a/tests/untried/pos/t1131.scala b/tests/pos/t1131.scala similarity index 100% rename from tests/untried/pos/t1131.scala rename to tests/pos/t1131.scala diff --git a/tests/untried/pos/t1133.scala b/tests/pos/t1133.scala similarity index 100% rename from tests/untried/pos/t1133.scala rename to tests/pos/t1133.scala diff --git a/tests/untried/pos/t1136.scala b/tests/pos/t1136.scala similarity index 100% rename from tests/untried/pos/t1136.scala rename to tests/pos/t1136.scala diff --git a/tests/untried/pos/t1146.scala b/tests/pos/t1146.scala similarity index 100% rename from tests/untried/pos/t1146.scala rename to tests/pos/t1146.scala diff --git a/tests/untried/pos/t1147.scala b/tests/pos/t1147.scala similarity index 100% rename from tests/untried/pos/t1147.scala rename to tests/pos/t1147.scala diff --git a/tests/untried/pos/t115.scala b/tests/pos/t115.scala similarity index 100% rename from tests/untried/pos/t115.scala rename to tests/pos/t115.scala diff --git a/tests/untried/pos/t1159.scala b/tests/pos/t1159.scala similarity index 100% rename from tests/untried/pos/t1159.scala rename to tests/pos/t1159.scala diff --git a/tests/untried/pos/t116.scala b/tests/pos/t116.scala similarity index 100% rename from tests/untried/pos/t116.scala rename to tests/pos/t116.scala diff --git a/tests/untried/pos/t1164.scala b/tests/pos/t1164.scala similarity index 100% rename from tests/untried/pos/t1164.scala rename to tests/pos/t1164.scala diff --git a/tests/untried/pos/t1168.scala b/tests/pos/t1168.scala similarity index 100% rename from tests/untried/pos/t1168.scala rename to tests/pos/t1168.scala diff --git a/tests/untried/pos/t1185.scala b/tests/pos/t1185.scala similarity index 100% rename from tests/untried/pos/t1185.scala rename to tests/pos/t1185.scala diff --git a/tests/untried/pos/t119.scala b/tests/pos/t119.scala similarity index 100% rename from tests/untried/pos/t119.scala rename to tests/pos/t119.scala diff --git a/tests/untried/pos/t1203a.scala b/tests/pos/t1203a.scala similarity index 100% rename from tests/untried/pos/t1203a.scala rename to tests/pos/t1203a.scala diff --git a/tests/untried/pos/t121.scala b/tests/pos/t121.scala similarity index 100% rename from tests/untried/pos/t121.scala rename to tests/pos/t121.scala diff --git a/tests/untried/pos/t1210a.scala b/tests/pos/t1210a.scala similarity index 100% rename from tests/untried/pos/t1210a.scala rename to tests/pos/t1210a.scala diff --git a/tests/untried/pos/t122.scala b/tests/pos/t122.scala similarity index 100% rename from tests/untried/pos/t122.scala rename to tests/pos/t122.scala diff --git a/tests/untried/pos/t1226.scala b/tests/pos/t1226.scala similarity index 100% rename from tests/untried/pos/t1226.scala rename to tests/pos/t1226.scala diff --git a/tests/untried/pos/t1236.scala b/tests/pos/t1236.scala similarity index 91% rename from tests/untried/pos/t1236.scala rename to tests/pos/t1236.scala index 75a1befd263c..a84cad0fb558 100644 --- a/tests/untried/pos/t1236.scala +++ b/tests/pos/t1236.scala @@ -4,7 +4,7 @@ trait Empty[E[_]] { object T { val ListEmpty = new Empty[List] { - def e[A] = Nil + def e[B] = Nil } def foo[F[_]](q:(String,String)) = "hello" diff --git a/tests/untried/pos/t1237.scala b/tests/pos/t1237.scala similarity index 100% rename from tests/untried/pos/t1237.scala rename to tests/pos/t1237.scala diff --git a/tests/untried/pos/t124.scala b/tests/pos/t124.scala similarity index 100% rename from tests/untried/pos/t124.scala rename to tests/pos/t124.scala diff --git a/tests/untried/pos/t1260.scala b/tests/pos/t1260.scala similarity index 100% rename from tests/untried/pos/t1260.scala rename to tests/pos/t1260.scala diff --git a/tests/untried/pos/t1272.scala b/tests/pos/t1272.scala similarity index 100% rename from tests/untried/pos/t1272.scala rename to tests/pos/t1272.scala diff --git a/tests/untried/pos/t1279a.scala b/tests/pos/t1279a.scala similarity index 100% rename from tests/untried/pos/t1279a.scala rename to tests/pos/t1279a.scala diff --git a/tests/untried/pos/t1280.scala b/tests/pos/t1280.scala similarity index 100% rename from tests/untried/pos/t1280.scala rename to tests/pos/t1280.scala diff --git a/tests/untried/pos/t1292.scala b/tests/pos/t1292.scala similarity index 92% rename from tests/untried/pos/t1292.scala rename to tests/pos/t1292.scala index 83a996d530a9..8e69734e97eb 100644 --- a/tests/untried/pos/t1292.scala +++ b/tests/pos/t1292.scala @@ -2,13 +2,14 @@ trait Foo[T <: Foo[T, Enum], Enum <: Enumeration] { type StV = Enum#Value type Meta = MegaFoo[T, Enum] - type Slog <: Enumeration + type Slog = Enumeration def getSingleton: Meta } trait MegaFoo[T <: Foo[T, Enum], Enum <: Enumeration] extends Foo[T, Enum] { def doSomething(what: T, misc: StV, dog: Meta#Event) = None + abstract class Event object Event @@ -23,8 +24,6 @@ object E extends Enumeration { class RFoo extends Foo[RFoo, E.type] { def getSingleton = MegaRFoo - - type Slog = E.type } object MegaRFoo extends RFoo with MegaFoo[RFoo, E.type] { diff --git a/tests/untried/pos/t0654.scala b/tests/untried/pos/t0654.scala deleted file mode 100644 index 07b4e727948d..000000000000 --- a/tests/untried/pos/t0654.scala +++ /dev/null @@ -1,5 +0,0 @@ -object Test { - class Foo[T] - type C[T] = Foo[_ <: T] - val a: C[AnyRef] = new Foo[AnyRef] -} diff --git a/tests/untried/pos/t0905.scala b/tests/untried/pos/t0905.scala deleted file mode 100644 index 8cd84759cf79..000000000000 --- a/tests/untried/pos/t0905.scala +++ /dev/null @@ -1,6 +0,0 @@ -object Test { - trait A[T] - def f(implicit p: A[T] forSome { type T } ) = null - implicit val x: A[T] forSome { type T } = null - println(f) -} diff --git a/tests/untried/pos/t1048.scala b/tests/untried/pos/t1048.scala deleted file mode 100644 index cd16db5b60cd..000000000000 --- a/tests/untried/pos/t1048.scala +++ /dev/null @@ -1,14 +0,0 @@ -trait T[U] { - def x: T[V] forSome { type V <: U } -} - -object T { - def unapply[U](t: T[U]): Option[T[V] forSome { type V <: U }] = Some(t.x) -} - -object Test { - def f[W](t: T[W]) = t match { - case T(T(_)) => () - } -} - diff --git a/tests/untried/pos/t1208.scala b/tests/untried/pos/t1208.scala deleted file mode 100644 index 9ac783d39a87..000000000000 --- a/tests/untried/pos/t1208.scala +++ /dev/null @@ -1,4 +0,0 @@ -object Test { - object Foo - val f: Option[Foo.type] = Some(Foo) -}