Skip to content

Commit

Permalink
Merge pull request scala#1006 from dotty-staging/more-tests
Browse files Browse the repository at this point in the history
More tests
  • Loading branch information
smarter committed Dec 26, 2015
2 parents c66613d + e51b884 commit 2427f05
Show file tree
Hide file tree
Showing 269 changed files with 115 additions and 306 deletions.
2 changes: 1 addition & 1 deletion docs/SyntaxSummary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ grammar.
| `_'
ExprInParens ::= PostfixExpr `:' Type
| Expr
BlockResult ::= (FunParams | [`implicit'] id `:' InfixType) => Block
BlockResult ::= (FunParams | [`implicit'] id `:' InfixType) `=>' Block
| Expr1
Expr1 ::= `if' `(' Expr `)' {nl} Expr [[semi] else Expr] If(Parens(cond), thenp, elsep?)
| `if' Expr `then' Expr [[semi] else Expr] If(cond, thenp, elsep?)
Expand Down
5 changes: 3 additions & 2 deletions src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 3 additions & 7 deletions src/dotty/tools/dotc/core/TypeApplications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
19 changes: 15 additions & 4 deletions src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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() }
}
12 changes: 8 additions & 4 deletions src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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 =>
Expand Down
3 changes: 2 additions & 1 deletion src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/transform/SuperAccessors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions src/dotty/tools/dotc/typer/EtaExpansion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This does not currently work because it mixes higher-kinded types and raw type constructors.
package dotty.collection
package immutable

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Type arguments on infix operators are not supported by the syntax
class A {
def fn1 = List apply 1
def fn2 = List apply[Int] 2
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This relies on the naming of the transformed classes which will have to change in the new stdlib.
import scala.collection._

trait Foo[+A,
Expand All @@ -6,12 +7,12 @@ trait Foo[+A,
extends Seq[A] with SeqLike[A, This] with IterableView[A, Coll] with IterableViewLike[A, Coll, This] {
self =>

trait Transformed[+B] extends SeqView[B, Coll] with super.Transformed[B] {
trait TransformedFoo[+B] extends SeqView[B, Coll] with super.Transformed[B] {
def length: Int
def apply(idx: Int): B
override def toString = viewToString
}
trait Reversed extends Transformed[A] {
trait Reversed extends TransformedFoo[A] {
override def iterator: Iterator[A] = createReversedIterator
def length: Int = self.length
def apply(idx: Int): A = self.apply(length - 1 - idx)
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ case class C2(checks: Check[_]*);
object C {
def m(x : C2): Any = (null: Any) match {
case C2(_, rest : _*) => {
// Invalid: Vararg pattern cannot be split between normal and :_* patterns.
// This split also does not work for vararg arguments, so there's no
// good argument it should work for patterns
rest.map(_.value)
}
}
Expand Down
16 changes: 16 additions & 0 deletions tests/invalid/pos/t3856.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
case class C[T](x: T)

case class CS(xs: C[_]*)

// t3856
object Test {
val x = CS(C(5), C("abc")) match { case CS(C(5), xs : _*) => xs }
// Invalid: Vararg pattern cannot be split between normal and :_* patterns.
// This split also does not work for vararg arguments, so there's no
// good argument it should work for patterns
println(x)

def foo(xs: Int*) = ()
val xs = List(1, 2, 3)
foo(1, xs:_*)
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Invalid because syntax has changed;
// template statements cannot be lambdas.
object t4202_1 {
() => {
trait T {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Invalid because structural types are not supported.
class A {
(new { def field = 0; def field_=(i: Int) = () }).field = 5 // compiles as expected
(new { def field(implicit i: Int) = 0; def field_=(i: Int) = () }).field = 5 // compiles even with implicit params on getter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Invalid because lambdas can no longer be tenmplate statements.
object Test {
trait Suite { def bar() = () }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Invalid because it relies on internal traits of views that will change their names.
import scala.collection._

trait SeqViewLike[+A,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Invalid because hk type parameters may not appear in lower bounds
trait VectorLike[+T, +V[A] <: Vector[A]] {
def +[S, VResult[S] >: V[S]](v: VResult[S]): Unit
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Invalid because nested hk type parameters are no longer allowed
import language._


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Invalid because nested hk type parameters are no longer allowed
import language.higherKinds

trait P [N1, +E1[X <: N1]]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion tests/pending/pos/sammy_poly.flags

This file was deleted.

1 change: 0 additions & 1 deletion tests/pending/pos/sealed-final.flags

This file was deleted.

File renamed without changes.
File renamed without changes.
24 changes: 0 additions & 24 deletions tests/pending/pos/t1843.scala

This file was deleted.

11 changes: 0 additions & 11 deletions tests/pending/pos/t2613.scala

This file was deleted.

1 change: 0 additions & 1 deletion tests/pending/pos/t3252.flags

This file was deleted.

9 changes: 0 additions & 9 deletions tests/pending/pos/t3856.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Currently takes a very long time (more than a minute) and then
// does not find an alternative.
object OverloadingShapeType {
// comment out this, and the other alternative is chosen.
def blerg(f: String): Unit = {}
Expand Down
5 changes: 0 additions & 5 deletions tests/pending/pos/t4176b.scala

This file was deleted.

2 changes: 1 addition & 1 deletion tests/pending/pos/t4269.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class A {
PartialFunction.condOpt(Nil) {
case items@List(_*) if true =>
case items@List(_: _*) if true =>
}
}
Loading

0 comments on commit 2427f05

Please sign in to comment.