Skip to content

Commit 2427f05

Browse files
committed
Merge pull request #1006 from dotty-staging/more-tests
More tests
2 parents c66613d + e51b884 commit 2427f05

File tree

269 files changed

+115
-306
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

269 files changed

+115
-306
lines changed

docs/SyntaxSummary.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ grammar.
129129
| `_'
130130
ExprInParens ::= PostfixExpr `:' Type
131131
| Expr
132-
BlockResult ::= (FunParams | [`implicit'] id `:' InfixType) => Block
132+
BlockResult ::= (FunParams | [`implicit'] id `:' InfixType) `=>' Block
133133
| Expr1
134134
Expr1 ::= `if' `(' Expr `)' {nl} Expr [[semi] else Expr] If(Parens(cond), thenp, elsep?)
135135
| `if' Expr `then' Expr [[semi] else Expr] If(cond, thenp, elsep?)

src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,8 @@ object desugar {
403403
// implicit wrapper is typechecked in same scope as constructor, so
404404
// we can reuse the constructor parameters; no derived params are needed.
405405
DefDef(name.toTermName, constrTparams, constrVparamss, classTypeRef, creatorExpr)
406-
.withFlags(Synthetic | Implicit) :: Nil
406+
.withFlags(Synthetic | Implicit)
407+
.withPos(cdef.pos) :: Nil
407408

408409

409410
val self1 = {
@@ -801,7 +802,7 @@ object desugar {
801802
tree match {
802803
case SymbolLit(str) =>
803804
Apply(
804-
Select(ref(defn.SymbolClass.companionModule.termRef), nme.apply),
805+
ref(defn.SymbolClass.companionModule.termRef),
805806
Literal(Constant(str)) :: Nil)
806807
case InterpolatedString(id, strs, elems) =>
807808
Apply(Select(Apply(Ident(nme.StringContext), strs), id), elems)

src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,13 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
234234
* parameter, the reference will be a repeated argument.
235235
*/
236236
def refOfDef(tree: MemberDef)(implicit ctx: Context) = tree match {
237-
case ValDef(_, PostfixOp(_, nme.raw.STAR), _) =>
238-
Typed(Ident(tree.name), Ident(tpnme.WILDCARD_STAR))
239-
case _ =>
240-
Ident(tree.name)
237+
case ValDef(_, PostfixOp(_, nme.raw.STAR), _) => repeated(Ident(tree.name))
238+
case _ => Ident(tree.name)
241239
}
242240

241+
/** A repeated argument such as `arg: _*` */
242+
def repeated(arg: Tree)(implicit ctx: Context) = Typed(arg, Ident(tpnme.WILDCARD_STAR))
243+
243244
// ------- Decorators -------------------------------------------------
244245

245246
implicit class UntypedTreeDecorator(val self: Tree) extends AnyVal {

src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,10 +591,7 @@ class Definitions {
591591
}
592592

593593
def isBottomClass(cls: Symbol) = cls == NothingClass || cls == NullClass
594-
def isBottomType(tp: Type) = tp match {
595-
case tp: TypeRef => isBottomClass(tp.symbol)
596-
case _ => false
597-
}
594+
def isBottomType(tp: Type) = tp.derivesFrom(NothingClass) || tp.derivesFrom(NullClass)
598595

599596
def isFunctionClass(cls: Symbol) = isVarArityClass(cls, tpnme.Function)
600597
def isAbstractFunctionClass(cls: Symbol) = isVarArityClass(cls, tpnme.AbstractFunction)

src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,14 +374,10 @@ class TypeApplications(val self: Type) extends AnyVal {
374374
//.ensuring(res => res.EtaReduce =:= self, s"res = $res, core = ${res.EtaReduce}, self = $self, hc = ${res.hashCode}")
375375
}
376376

377-
/** Eta expand the prefix in front of any refinements.
378-
* @param tparamsForBottom Type parameters to use if core is a bottom type
379-
*/
380-
def EtaExpandCore(tparamsForBottom: List[TypeSymbol])(implicit ctx: Context): Type = self.stripTypeVar match {
377+
/** Eta expand the prefix in front of any refinements. */
378+
def EtaExpandCore(implicit ctx: Context): Type = self.stripTypeVar match {
381379
case self: RefinedType =>
382-
self.derivedRefinedType(self.parent.EtaExpandCore(tparamsForBottom), self.refinedName, self.refinedInfo)
383-
case tp: TypeRef if defn.isBottomClass(tp.symbol) =>
384-
self.LambdaAbstract(tparamsForBottom)
380+
self.derivedRefinedType(self.parent.EtaExpandCore, self.refinedName, self.refinedInfo)
385381
case _ =>
386382
self.EtaExpand(self.typeParams)
387383
}

src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
124124
pendingSubTypes = new mutable.HashSet[(Type, Type)]
125125
ctx.log(s"!!! deep subtype recursion involving ${tp1.show} <:< ${tp2.show}, constraint = ${state.constraint.show}")
126126
ctx.log(s"!!! constraint = ${constraint.show}")
127-
if (ctx.settings.YnoDeepSubtypes.value) throw new Error("deep subtype")
127+
assert(!ctx.settings.YnoDeepSubtypes.value) //throw new Error("deep subtype")
128128
if (Config.traceDeepSubTypeRecursions && !this.isInstanceOf[ExplainingTypeComparer])
129129
ctx.log(TypeComparer.explained(implicit ctx => ctx.typeComparer.isSubType(tp1, tp2)))
130130
}
@@ -598,7 +598,11 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
598598
other.isInstanceOf[TypeRef] &&
599599
args.length == other.typeParams.length && {
600600
val applied = other.appliedTo(argRefs(rt, args.length))
601-
if (inOrder) isSubType(body, applied) else isSubType(applied, body)
601+
if (inOrder) isSubType(body, applied)
602+
else body match {
603+
case body: TypeBounds => body.contains(applied)
604+
case _ => isSubType(applied, body)
605+
}
602606
}
603607
case _ =>
604608
false
@@ -1233,7 +1237,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
12331237

12341238
/** Show subtype goal that led to an assertion failure */
12351239
def showGoal(tp1: Type, tp2: Type)(implicit ctx: Context) = {
1236-
ctx.println(disambiguated(implicit ctx => s"assertion failure for ${tp1.show} <:< ${tp2.show}, frozen = $frozenConstraint"))
1240+
println(disambiguated(implicit ctx => s"assertion failure for ${tp1.show} <:< ${tp2.show}, frozen = $frozenConstraint"))
12371241
def explainPoly(tp: Type) = tp match {
12381242
case tp: PolyParam => ctx.println(s"polyparam ${tp.show} found in ${tp.binder.show}")
12391243
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) {
13231327

13241328
override def compareHkApply(projection: NamedType, other: Type, inOrder: Boolean) =
13251329
if (projection.name == tpnme.hkApply)
1326-
traceIndented(i"compareHK $projection, $other, $inOrder") {
1330+
traceIndented(i"compareHkApply $projection, $other, $inOrder") {
13271331
super.compareHkApply(projection, other, inOrder)
13281332
}
13291333
else super.compareHkApply(projection, other, inOrder)
13301334

1335+
override def compareHkLambda(rt: RefinedType, other: Type, inOrder: Boolean) =
1336+
if (rt.refinedName == tpnme.hkApply)
1337+
traceIndented(i"compareHkLambda $rt, $other, $inOrder") {
1338+
super.compareHkLambda(rt, other, inOrder)
1339+
}
1340+
else super.compareHkLambda(rt, other, inOrder)
1341+
13311342
override def toString = "Subtype trace:" + { try b.toString finally b.clear() }
13321343
}

src/dotty/tools/dotc/core/Types.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,8 +1554,10 @@ object Types {
15541554
*
15551555
* T#A --> B if A is bound to an alias `= B` in T
15561556
*
1557-
* (S & T)#A --> S#A if T does not have a member namd A
1558-
* --> T#A if S does not have a member namd A
1557+
* If Config.splitProjections is set:
1558+
*
1559+
* (S & T)#A --> S#A if T does not have a member named A
1560+
* --> T#A if S does not have a member named A
15591561
* --> S#A & T#A otherwise
15601562
* (S | T)#A --> S#A | T#A
15611563
*/
@@ -1564,11 +1566,13 @@ object Types {
15641566
else if (isType) {
15651567
val res = prefix.lookupRefined(name)
15661568
if (res.exists) res
1567-
else if (name == tpnme.hkApply && prefix.classNotLambda)
1569+
else if (name == tpnme.hkApply && prefix.classNotLambda) {
15681570
// After substitution we might end up with a type like
15691571
// `C { type hk$0 = T0; ...; type hk$n = Tn } # $Apply`
15701572
// where C is a class. In that case we eta expand `C`.
1571-
derivedSelect(prefix.EtaExpandCore(this.prefix.typeConstructor.typeParams))
1573+
if (defn.isBottomType(prefix)) prefix.classSymbol.typeRef
1574+
else derivedSelect(prefix.EtaExpandCore)
1575+
}
15721576
else if (Config.splitProjections)
15731577
prefix match {
15741578
case prefix: AndType =>

src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,8 @@ object Parsers {
11561156
*/
11571157
def block(): Tree = {
11581158
val stats = blockStatSeq()
1159-
if (stats.nonEmpty && !stats.last.isDef) Block(stats.init, stats.last)
1159+
def isExpr(stat: Tree) = !(stat.isDef || stat.isInstanceOf[Import])
1160+
if (stats.nonEmpty && isExpr(stats.last)) Block(stats.init, stats.last)
11601161
else Block(stats, EmptyTree)
11611162
}
11621163

src/dotty/tools/dotc/transform/SuperAccessors.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class SuperAccessors(thisTransformer: DenotTransformer) {
112112
ctx.error(
113113
i"${sym.showLocated} is accessed from super. It may not be abstract unless it is overridden by a member declared `abstract' and `override'",
114114
sel.pos)
115-
else println(i"ok super $sel ${sym.showLocated} $member $clazz ${member.isIncompleteIn(clazz)}")
115+
else ctx.log(i"ok super $sel ${sym.showLocated} $member $clazz ${member.isIncompleteIn(clazz)}")
116116
}
117117
else if (mix == tpnme.EMPTY && !(sym.owner is Trait))
118118
// SI-4989 Check if an intermediate class between `clazz` and `sym.owner` redeclares the method as abstract.

src/dotty/tools/dotc/typer/EtaExpansion.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ object EtaExpansion {
141141
else mt.paramTypes map TypeTree
142142
val params = (mt.paramNames, paramTypes).zipped.map((name, tpe) =>
143143
ValDef(name, TypeTree(tpe), EmptyTree).withFlags(Synthetic | Param).withPos(tree.pos))
144-
val ids = mt.paramNames map (name =>
145-
Ident(name).withPos(tree.pos))
144+
var ids: List[Tree] = mt.paramNames map (name => Ident(name).withPos(tree.pos))
145+
if (mt.paramTypes.nonEmpty && mt.paramTypes.last.isRepeatedParam)
146+
ids = ids.init :+ repeated(ids.last)
146147
val body = Apply(lifted, ids)
147148
val fn = untpd.Function(params, body)
148149
if (defs.nonEmpty) untpd.Block(defs.toList map untpd.TypedSplice, fn) else fn

src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ object RefChecks {
211211
if (!(hasErrors && member.is(Synthetic) && member.is(Module))) {
212212
// suppress errors relating toi synthetic companion objects if other override
213213
// errors (e.g. relating to the companion class) have already been reported.
214-
if (member.owner == clazz) ctx.error(fullmsg, member.pos)
214+
if (member.owner == clazz) ctx.error(fullmsg+", member = $member", member.pos)
215215
else mixinOverrideErrors += new MixinOverrideError(member, fullmsg)
216216
hasErrors = true
217217
}
@@ -221,6 +221,11 @@ object RefChecks {
221221
emitOverrideError(overrideErrorMsg(msg))
222222
}
223223

224+
def autoOverride(sym: Symbol) =
225+
sym.is(Synthetic) && (
226+
desugar.isDesugaredCaseClassMethodName(member.name) || // such names are added automatically, can't have an override preset.
227+
sym.is(Module)) // synthetic companion
228+
224229
def overrideAccessError() = {
225230
ctx.log(i"member: ${member.showLocated} ${member.flags}") // DEBUG
226231
ctx.log(i"other: ${other.showLocated} ${other.flags}") // DEBUG
@@ -300,7 +305,7 @@ object RefChecks {
300305
!member.isAnyOverride) {
301306
// (*) Exclusion for default getters, fixes SI-5178. We cannot assign the Override flag to
302307
// the default getter: one default getter might sometimes override, sometimes not. Example in comment on ticket.
303-
if (member.is(Synthetic) && desugar.isDesugaredCaseClassMethodName(member.name)) // such names are added automatically, can't have an override preset.
308+
if (autoOverride(member))
304309
member.setFlag(Override)
305310
else if (member.owner != clazz && other.owner != clazz && !(other.owner derivesFrom member.owner))
306311
emitOverrideError(

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
165165
tree.pos)
166166
found
167167
}
168-
val Name = name.toTermName
168+
val Name = name.toTermName.decode
169169
selectors match {
170170
case Pair(Ident(from), Ident(Name)) :: rest =>
171171
val selName = if (name.isTypeName) from.toTypeName else from

tests/pending/pos/IterableSelfRec.scala renamed to tests/invalid/pos/IterableSelfRec.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This does not currently work because it mixes higher-kinded types and raw type constructors.
12
package dotty.collection
23
package immutable
34

File renamed without changes.

tests/pending/pos/dotless-targs.scala renamed to tests/invalid/pos/dotless-targs.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Type arguments on infix operators are not supported by the syntax
12
class A {
23
def fn1 = List apply 1
34
def fn2 = List apply[Int] 2
File renamed without changes.
File renamed without changes.

tests/pending/pos/specializes-sym-crash.scala renamed to tests/invalid/pos/specializes-sym-crash.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This relies on the naming of the transformed classes which will have to change in the new stdlib.
12
import scala.collection._
23

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

9-
trait Transformed[+B] extends SeqView[B, Coll] with super.Transformed[B] {
10+
trait TransformedFoo[+B] extends SeqView[B, Coll] with super.Transformed[B] {
1011
def length: Int
1112
def apply(idx: Int): B
1213
override def toString = viewToString
1314
}
14-
trait Reversed extends Transformed[A] {
15+
trait Reversed extends TransformedFoo[A] {
1516
override def iterator: Iterator[A] = createReversedIterator
1617
def length: Int = self.length
1718
def apply(idx: Int): A = self.apply(length - 1 - idx)
File renamed without changes.

tests/pending/pos/t3577.scala renamed to tests/invalid/pos/t3577.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ case class C2(checks: Check[_]*);
55
object C {
66
def m(x : C2): Any = (null: Any) match {
77
case C2(_, rest : _*) => {
8+
// Invalid: Vararg pattern cannot be split between normal and :_* patterns.
9+
// This split also does not work for vararg arguments, so there's no
10+
// good argument it should work for patterns
811
rest.map(_.value)
912
}
1013
}

tests/invalid/pos/t3856.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
case class C[T](x: T)
2+
3+
case class CS(xs: C[_]*)
4+
5+
// t3856
6+
object Test {
7+
val x = CS(C(5), C("abc")) match { case CS(C(5), xs : _*) => xs }
8+
// Invalid: Vararg pattern cannot be split between normal and :_* patterns.
9+
// This split also does not work for vararg arguments, so there's no
10+
// good argument it should work for patterns
11+
println(x)
12+
13+
def foo(xs: Int*) = ()
14+
val xs = List(1, 2, 3)
15+
foo(1, xs:_*)
16+
}

tests/pending/pos/t4202.scala renamed to tests/invalid/pos/t4202.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Invalid because syntax has changed;
2+
// template statements cannot be lambdas.
13
object t4202_1 {
24
() => {
35
trait T {

tests/pending/pos/t4237.scala renamed to tests/invalid/pos/t4237.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Invalid because structural types are not supported.
12
class A {
23
(new { def field = 0; def field_=(i: Int) = () }).field = 5 // compiles as expected
34
(new { def field(implicit i: Int) = 0; def field_=(i: Int) = () }).field = 5 // compiles even with implicit params on getter

tests/pending/pos/t4363.scala renamed to tests/invalid/pos/t4363.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Invalid because lambdas can no longer be tenmplate statements.
12
object Test {
23
trait Suite { def bar() = () }
34

tests/pending/pos/t4365/a_1.scala renamed to tests/invalid/pos/t4365/a_1.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Invalid because it relies on internal traits of views that will change their names.
12
import scala.collection._
23

34
trait SeqViewLike[+A,
File renamed without changes.

tests/pending/pos/t4553.scala renamed to tests/invalid/pos/t4553.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Invalid because hk type parameters may not appear in lower bounds
12
trait VectorLike[+T, +V[A] <: Vector[A]] {
23
def +[S, VResult[S] >: V[S]](v: VResult[S]): Unit
34
}
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.

tests/pending/pos/t8023.scala renamed to tests/invalid/pos/t8023.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Invalid because nested hk type parameters are no longer allowed
12
import language._
23

34

File renamed without changes.

tests/pending/pos/t8224.scala renamed to tests/invalid/pos/t8224.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Invalid because nested hk type parameters are no longer allowed
12
import language.higherKinds
23

34
trait P [N1, +E1[X <: N1]]
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.

tests/pending/pos/sammy_poly.flags

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/pending/pos/sealed-final.flags

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/pending/pos/t1843.scala

Lines changed: 0 additions & 24 deletions
This file was deleted.

tests/pending/pos/t2613.scala

Lines changed: 0 additions & 11 deletions
This file was deleted.

tests/pending/pos/t3252.flags

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/pending/pos/t3856.scala

Lines changed: 0 additions & 9 deletions
This file was deleted.

tests/untried/pos/t3862.scala renamed to tests/pending/pos/t3862.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Currently takes a very long time (more than a minute) and then
2+
// does not find an alternative.
13
object OverloadingShapeType {
24
// comment out this, and the other alternative is chosen.
35
def blerg(f: String): Unit = {}

tests/pending/pos/t4176b.scala

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/pending/pos/t4269.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class A {
22
PartialFunction.condOpt(Nil) {
3-
case items@List(_*) if true =>
3+
case items@List(_: _*) if true =>
44
}
55
}

0 commit comments

Comments
 (0)