aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Martres <smarter@ubuntu.com>2015-12-26 22:12:57 +0100
committerGuillaume Martres <smarter@ubuntu.com>2015-12-26 22:12:57 +0100
commit2427f056447ab3f9a0ceaa001353eb0a4067e1bb (patch)
treeb9013e390a217a2da5f46401164958adf44d48de /src
parentc66613de7f32cfabbca765a96f1a3cc0ea2d5bcb (diff)
parente51b8845fb20fe3a4e1c655d4b72e2833906bbc2 (diff)
downloaddotty-2427f056447ab3f9a0ceaa001353eb0a4067e1bb.tar.gz
dotty-2427f056447ab3f9a0ceaa001353eb0a4067e1bb.tar.bz2
dotty-2427f056447ab3f9a0ceaa001353eb0a4067e1bb.zip
Merge pull request #1006 from dotty-staging/more-tests
More tests
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/ast/Desugar.scala5
-rw-r--r--src/dotty/tools/dotc/ast/untpd.scala9
-rw-r--r--src/dotty/tools/dotc/core/Definitions.scala5
-rw-r--r--src/dotty/tools/dotc/core/TypeApplications.scala10
-rw-r--r--src/dotty/tools/dotc/core/TypeComparer.scala19
-rw-r--r--src/dotty/tools/dotc/core/Types.scala12
-rw-r--r--src/dotty/tools/dotc/parsing/Parsers.scala3
-rw-r--r--src/dotty/tools/dotc/transform/SuperAccessors.scala2
-rw-r--r--src/dotty/tools/dotc/typer/EtaExpansion.scala5
-rw-r--r--src/dotty/tools/dotc/typer/RefChecks.scala9
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala2
11 files changed, 49 insertions, 32 deletions
diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala
index 12f3e4406..87694843a 100644
--- a/src/dotty/tools/dotc/ast/Desugar.scala
+++ b/src/dotty/tools/dotc/ast/Desugar.scala
@@ -403,7 +403,8 @@ object desugar {
// implicit wrapper is typechecked in same scope as constructor, so
// we can reuse the constructor parameters; no derived params are needed.
DefDef(name.toTermName, constrTparams, constrVparamss, classTypeRef, creatorExpr)
- .withFlags(Synthetic | Implicit) :: Nil
+ .withFlags(Synthetic | Implicit)
+ .withPos(cdef.pos) :: Nil
val self1 = {
@@ -801,7 +802,7 @@ object desugar {
tree match {
case SymbolLit(str) =>
Apply(
- Select(ref(defn.SymbolClass.companionModule.termRef), nme.apply),
+ ref(defn.SymbolClass.companionModule.termRef),
Literal(Constant(str)) :: Nil)
case InterpolatedString(id, strs, elems) =>
Apply(Select(Apply(Ident(nme.StringContext), strs), id), elems)
diff --git a/src/dotty/tools/dotc/ast/untpd.scala b/src/dotty/tools/dotc/ast/untpd.scala
index 28a3cf1ff..85052a4da 100644
--- a/src/dotty/tools/dotc/ast/untpd.scala
+++ b/src/dotty/tools/dotc/ast/untpd.scala
@@ -234,12 +234,13 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
* parameter, the reference will be a repeated argument.
*/
def refOfDef(tree: MemberDef)(implicit ctx: Context) = tree match {
- case ValDef(_, PostfixOp(_, nme.raw.STAR), _) =>
- Typed(Ident(tree.name), Ident(tpnme.WILDCARD_STAR))
- case _ =>
- Ident(tree.name)
+ case ValDef(_, PostfixOp(_, nme.raw.STAR), _) => repeated(Ident(tree.name))
+ case _ => Ident(tree.name)
}
+ /** A repeated argument such as `arg: _*` */
+ def repeated(arg: Tree)(implicit ctx: Context) = Typed(arg, Ident(tpnme.WILDCARD_STAR))
+
// ------- Decorators -------------------------------------------------
implicit class UntypedTreeDecorator(val self: Tree) extends AnyVal {
diff --git a/src/dotty/tools/dotc/core/Definitions.scala b/src/dotty/tools/dotc/core/Definitions.scala
index 609cce189..cbb3f1083 100644
--- a/src/dotty/tools/dotc/core/Definitions.scala
+++ b/src/dotty/tools/dotc/core/Definitions.scala
@@ -591,10 +591,7 @@ class Definitions {
}
def isBottomClass(cls: Symbol) = cls == NothingClass || cls == NullClass
- def isBottomType(tp: Type) = tp match {
- case tp: TypeRef => isBottomClass(tp.symbol)
- case _ => false
- }
+ def isBottomType(tp: Type) = tp.derivesFrom(NothingClass) || tp.derivesFrom(NullClass)
def isFunctionClass(cls: Symbol) = isVarArityClass(cls, tpnme.Function)
def isAbstractFunctionClass(cls: Symbol) = isVarArityClass(cls, tpnme.AbstractFunction)
diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala
index 8aea3381a..aab327ce9 100644
--- a/src/dotty/tools/dotc/core/TypeApplications.scala
+++ b/src/dotty/tools/dotc/core/TypeApplications.scala
@@ -374,14 +374,10 @@ class TypeApplications(val self: Type) extends AnyVal {
//.ensuring(res => res.EtaReduce =:= self, s"res = $res, core = ${res.EtaReduce}, self = $self, hc = ${res.hashCode}")
}
- /** Eta expand the prefix in front of any refinements.
- * @param tparamsForBottom Type parameters to use if core is a bottom type
- */
- def EtaExpandCore(tparamsForBottom: List[TypeSymbol])(implicit ctx: Context): Type = self.stripTypeVar match {
+ /** Eta expand the prefix in front of any refinements. */
+ def EtaExpandCore(implicit ctx: Context): Type = self.stripTypeVar match {
case self: RefinedType =>
- self.derivedRefinedType(self.parent.EtaExpandCore(tparamsForBottom), self.refinedName, self.refinedInfo)
- case tp: TypeRef if defn.isBottomClass(tp.symbol) =>
- self.LambdaAbstract(tparamsForBottom)
+ self.derivedRefinedType(self.parent.EtaExpandCore, self.refinedName, self.refinedInfo)
case _ =>
self.EtaExpand(self.typeParams)
}
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala
index 1e90bd6c8..d5d811542 100644
--- a/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -124,7 +124,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
pendingSubTypes = new mutable.HashSet[(Type, Type)]
ctx.log(s"!!! deep subtype recursion involving ${tp1.show} <:< ${tp2.show}, constraint = ${state.constraint.show}")
ctx.log(s"!!! constraint = ${constraint.show}")
- if (ctx.settings.YnoDeepSubtypes.value) throw new Error("deep subtype")
+ assert(!ctx.settings.YnoDeepSubtypes.value) //throw new Error("deep subtype")
if (Config.traceDeepSubTypeRecursions && !this.isInstanceOf[ExplainingTypeComparer])
ctx.log(TypeComparer.explained(implicit ctx => ctx.typeComparer.isSubType(tp1, tp2)))
}
@@ -598,7 +598,11 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
other.isInstanceOf[TypeRef] &&
args.length == other.typeParams.length && {
val applied = other.appliedTo(argRefs(rt, args.length))
- if (inOrder) isSubType(body, applied) else isSubType(applied, body)
+ if (inOrder) isSubType(body, applied)
+ else body match {
+ case body: TypeBounds => body.contains(applied)
+ case _ => isSubType(applied, body)
+ }
}
case _ =>
false
@@ -1233,7 +1237,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
/** Show subtype goal that led to an assertion failure */
def showGoal(tp1: Type, tp2: Type)(implicit ctx: Context) = {
- ctx.println(disambiguated(implicit ctx => s"assertion failure for ${tp1.show} <:< ${tp2.show}, frozen = $frozenConstraint"))
+ println(disambiguated(implicit ctx => s"assertion failure for ${tp1.show} <:< ${tp2.show}, frozen = $frozenConstraint"))
def explainPoly(tp: Type) = tp match {
case tp: PolyParam => ctx.println(s"polyparam ${tp.show} found in ${tp.binder.show}")
case tp: TypeRef if tp.symbol.exists => ctx.println(s"typeref ${tp.show} found in ${tp.symbol.owner.show}")
@@ -1323,10 +1327,17 @@ class ExplainingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
override def compareHkApply(projection: NamedType, other: Type, inOrder: Boolean) =
if (projection.name == tpnme.hkApply)
- traceIndented(i"compareHK $projection, $other, $inOrder") {
+ traceIndented(i"compareHkApply $projection, $other, $inOrder") {
super.compareHkApply(projection, other, inOrder)
}
else super.compareHkApply(projection, other, inOrder)
+ override def compareHkLambda(rt: RefinedType, other: Type, inOrder: Boolean) =
+ if (rt.refinedName == tpnme.hkApply)
+ traceIndented(i"compareHkLambda $rt, $other, $inOrder") {
+ super.compareHkLambda(rt, other, inOrder)
+ }
+ else super.compareHkLambda(rt, other, inOrder)
+
override def toString = "Subtype trace:" + { try b.toString finally b.clear() }
}
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index e0e9a535f..b72185492 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -1554,8 +1554,10 @@ object Types {
*
* T#A --> B if A is bound to an alias `= B` in T
*
- * (S & T)#A --> S#A if T does not have a member namd A
- * --> T#A if S does not have a member namd A
+ * If Config.splitProjections is set:
+ *
+ * (S & T)#A --> S#A if T does not have a member named A
+ * --> T#A if S does not have a member named A
* --> S#A & T#A otherwise
* (S | T)#A --> S#A | T#A
*/
@@ -1564,11 +1566,13 @@ object Types {
else if (isType) {
val res = prefix.lookupRefined(name)
if (res.exists) res
- else if (name == tpnme.hkApply && prefix.classNotLambda)
+ else if (name == tpnme.hkApply && prefix.classNotLambda) {
// After substitution we might end up with a type like
// `C { type hk$0 = T0; ...; type hk$n = Tn } # $Apply`
// where C is a class. In that case we eta expand `C`.
- derivedSelect(prefix.EtaExpandCore(this.prefix.typeConstructor.typeParams))
+ if (defn.isBottomType(prefix)) prefix.classSymbol.typeRef
+ else derivedSelect(prefix.EtaExpandCore)
+ }
else if (Config.splitProjections)
prefix match {
case prefix: AndType =>
diff --git a/src/dotty/tools/dotc/parsing/Parsers.scala b/src/dotty/tools/dotc/parsing/Parsers.scala
index 71a03b9e2..d59e087cb 100644
--- a/src/dotty/tools/dotc/parsing/Parsers.scala
+++ b/src/dotty/tools/dotc/parsing/Parsers.scala
@@ -1156,7 +1156,8 @@ object Parsers {
*/
def block(): Tree = {
val stats = blockStatSeq()
- if (stats.nonEmpty && !stats.last.isDef) Block(stats.init, stats.last)
+ def isExpr(stat: Tree) = !(stat.isDef || stat.isInstanceOf[Import])
+ if (stats.nonEmpty && isExpr(stats.last)) Block(stats.init, stats.last)
else Block(stats, EmptyTree)
}
diff --git a/src/dotty/tools/dotc/transform/SuperAccessors.scala b/src/dotty/tools/dotc/transform/SuperAccessors.scala
index 2febd2673..ae9c493ae 100644
--- a/src/dotty/tools/dotc/transform/SuperAccessors.scala
+++ b/src/dotty/tools/dotc/transform/SuperAccessors.scala
@@ -112,7 +112,7 @@ class SuperAccessors(thisTransformer: DenotTransformer) {
ctx.error(
i"${sym.showLocated} is accessed from super. It may not be abstract unless it is overridden by a member declared `abstract' and `override'",
sel.pos)
- else println(i"ok super $sel ${sym.showLocated} $member $clazz ${member.isIncompleteIn(clazz)}")
+ else ctx.log(i"ok super $sel ${sym.showLocated} $member $clazz ${member.isIncompleteIn(clazz)}")
}
else if (mix == tpnme.EMPTY && !(sym.owner is Trait))
// SI-4989 Check if an intermediate class between `clazz` and `sym.owner` redeclares the method as abstract.
diff --git a/src/dotty/tools/dotc/typer/EtaExpansion.scala b/src/dotty/tools/dotc/typer/EtaExpansion.scala
index 89415024e..aa210e6ed 100644
--- a/src/dotty/tools/dotc/typer/EtaExpansion.scala
+++ b/src/dotty/tools/dotc/typer/EtaExpansion.scala
@@ -141,8 +141,9 @@ object EtaExpansion {
else mt.paramTypes map TypeTree
val params = (mt.paramNames, paramTypes).zipped.map((name, tpe) =>
ValDef(name, TypeTree(tpe), EmptyTree).withFlags(Synthetic | Param).withPos(tree.pos))
- val ids = mt.paramNames map (name =>
- Ident(name).withPos(tree.pos))
+ var ids: List[Tree] = mt.paramNames map (name => Ident(name).withPos(tree.pos))
+ if (mt.paramTypes.nonEmpty && mt.paramTypes.last.isRepeatedParam)
+ ids = ids.init :+ repeated(ids.last)
val body = Apply(lifted, ids)
val fn = untpd.Function(params, body)
if (defs.nonEmpty) untpd.Block(defs.toList map untpd.TypedSplice, fn) else fn
diff --git a/src/dotty/tools/dotc/typer/RefChecks.scala b/src/dotty/tools/dotc/typer/RefChecks.scala
index 00518278c..7ccb3d103 100644
--- a/src/dotty/tools/dotc/typer/RefChecks.scala
+++ b/src/dotty/tools/dotc/typer/RefChecks.scala
@@ -211,7 +211,7 @@ object RefChecks {
if (!(hasErrors && member.is(Synthetic) && member.is(Module))) {
// suppress errors relating toi synthetic companion objects if other override
// errors (e.g. relating to the companion class) have already been reported.
- if (member.owner == clazz) ctx.error(fullmsg, member.pos)
+ if (member.owner == clazz) ctx.error(fullmsg+", member = $member", member.pos)
else mixinOverrideErrors += new MixinOverrideError(member, fullmsg)
hasErrors = true
}
@@ -221,6 +221,11 @@ object RefChecks {
emitOverrideError(overrideErrorMsg(msg))
}
+ def autoOverride(sym: Symbol) =
+ sym.is(Synthetic) && (
+ desugar.isDesugaredCaseClassMethodName(member.name) || // such names are added automatically, can't have an override preset.
+ sym.is(Module)) // synthetic companion
+
def overrideAccessError() = {
ctx.log(i"member: ${member.showLocated} ${member.flags}") // DEBUG
ctx.log(i"other: ${other.showLocated} ${other.flags}") // DEBUG
@@ -300,7 +305,7 @@ object RefChecks {
!member.isAnyOverride) {
// (*) Exclusion for default getters, fixes SI-5178. We cannot assign the Override flag to
// the default getter: one default getter might sometimes override, sometimes not. Example in comment on ticket.
- if (member.is(Synthetic) && desugar.isDesugaredCaseClassMethodName(member.name)) // such names are added automatically, can't have an override preset.
+ if (autoOverride(member))
member.setFlag(Override)
else if (member.owner != clazz && other.owner != clazz && !(other.owner derivesFrom member.owner))
emitOverrideError(
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 67fad1ad0..cb3bb0f20 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -165,7 +165,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
tree.pos)
found
}
- val Name = name.toTermName
+ val Name = name.toTermName.decode
selectors match {
case Pair(Ident(from), Ident(Name)) :: rest =>
val selName = if (name.isTypeName) from.toTypeName else from