Skip to content

Commit 8aed4a0

Browse files
authored
Merge pull request #5999 from dotty-staging/fix-i5001
Fix #5001: add test
2 parents 7d30a83 + 3224f33 commit 8aed4a0

21 files changed

+41
-9
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
308308
def AnonClass(parents: List[Type], fns: List[TermSymbol], methNames: List[TermName])(implicit ctx: Context): Block = {
309309
val owner = fns.head.owner
310310
val parents1 =
311-
if (parents.head.classSymbol.is(Trait)) parents.head.parents.head :: parents
311+
if (parents.head.classSymbol.is(Trait)) {
312+
val head = parents.head.parents.head
313+
if (head.isRef(defn.AnyClass)) defn.AnyRefType :: parents else head :: parents
314+
}
312315
else parents
313316
val cls = ctx.newNormalizedClassSymbol(owner, tpnme.ANON_CLASS, Synthetic | Final, parents1,
314317
coord = fns.map(_.span).reduceLeft(_ union _))

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ class Definitions {
184184
arr
185185
}
186186

187-
private def completeClass(cls: ClassSymbol): ClassSymbol = {
188-
ensureConstructor(cls, EmptyScope)
187+
private def completeClass(cls: ClassSymbol, ensureCtor: Boolean = true): ClassSymbol = {
188+
if (ensureCtor) ensureConstructor(cls, EmptyScope)
189189
if (cls.linkedClass.exists) cls.linkedClass.info = NoType
190190
cls
191191
}
@@ -262,7 +262,7 @@ class Definitions {
262262
* def getClass: java.lang.Class[T] = ???
263263
* }
264264
*/
265-
lazy val AnyClass: ClassSymbol = completeClass(enterCompleteClassSymbol(ScalaPackageClass, tpnme.Any, Abstract, Nil))
265+
lazy val AnyClass: ClassSymbol = completeClass(enterCompleteClassSymbol(ScalaPackageClass, tpnme.Any, Abstract, Nil), ensureCtor = false)
266266
def AnyType: TypeRef = AnyClass.typeRef
267267
lazy val AnyValClass: ClassSymbol = completeClass(enterCompleteClassSymbol(ScalaPackageClass, tpnme.AnyVal, Abstract, List(AnyClass.typeRef)))
268268
def AnyValType: TypeRef = AnyValClass.typeRef

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ class Typer extends Namer
517517
case templ: untpd.Template =>
518518
import untpd._
519519
var templ1 = templ
520-
def isEligible(tp: Type) = tp.exists && !tp.typeSymbol.is(Final)
520+
def isEligible(tp: Type) = tp.exists && !tp.typeSymbol.is(Final) && !tp.isRef(defn.AnyClass)
521521
if (templ1.parents.isEmpty &&
522522
isFullyDefined(pt, ForceDegree.noBottom) &&
523523
isEligible(pt.underlyingClassRef(refinementOK = false)))

library/src/scala/tasty/reflect/Printers.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,7 @@ trait Printers
10341034
case Term.Select(qual, _) => rec(qual)
10351035
case Term.Apply(fn, _) => rec(fn)
10361036
case Term.TypeApply(fn, _) => rec(fn)
1037+
case Term.Typed(_, _) => this += doubleLineBreak()
10371038
case _ => this += lineBreak()
10381039
}
10391040
next match {

tests/neg/i4820.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Foo[A]
2+
class Bar[A] extends Foo // error

tests/neg/i4820b.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
trait SetOps[A, +C <: SetOps[A, C]] {
2+
def concat(that: Iterable[A]): C = ???
3+
}
4+
5+
class Set1[A] extends SetOps // error: should be SetOps[A, Set1[A]]

tests/neg/i4820c.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
trait Foo[A]
2+
class Bar[A] extends Foo // error

tests/neg/i5001.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
case class i1() extends Any // error: Any does not have a constructor

tests/pending/fuzzy/AE-3b3b6b8b578c2152ae06a6647f65684de4d4605d.scala

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

tests/pos/i0306.decompiled

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ object bar {
44
val y: scala.collection.Seq[_ >: scala.Nothing <: scala.Any] = bar.x match {
55
case x: bar.C[u] =>
66
def xx: u = xx
7+
78
((xx: u): scala.collection.Seq[_ >: scala.Nothing <: scala.Any])
89
}
910
val z: java.lang.String = {
1011
def xx: scala.Predef.String = xx
12+
1113
(xx: java.lang.String)
1214
}
13-
}
15+
}

tests/pos/i5001.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
case class i1() extends AnyRef

tests/pos/simpleRefinement.decompiled

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Foo() {
3232
def w[T]: scala.Predef.String = "a"
3333
def w2[T](a: scala.Null)(b: scala.Null): scala.Null = null
3434
}
35+
3536
(new $anon(): Bar {
3637
type S >: scala.Int <: scala.Int
3738
type T >: scala.Function1[scala.Int, scala.Int] <: scala.Function1[scala.Int, scala.Int]
@@ -44,4 +45,4 @@ class Foo() {
4445
def w2[T >: scala.Nothing <: scala.Any](a: scala.Null)(b: scala.Null): scala.Null
4546
})
4647
}
47-
}
48+
}

tests/run-with-compiler/i3876-c.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
val f: scala.Function1[scala.Int, scala.Int] {
55
def apply(x: scala.Int): scala.Int
66
} = ((x: scala.Int) => x.+(x))
7+
78
(f: scala.Function1[scala.Int, scala.Int] {
89
def apply(x: scala.Int): scala.Int
910
}).apply(x$1)

tests/run-with-compiler/quote-nested-3.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
type T = scala.Predef.String
33
val x: java.lang.String = "foo"
44
val z: T = x
5+
56
(x: java.lang.String)
67
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
val t: scala.quoted.Type[scala.Predef.String] = scala.quoted.Type.apply[scala.Predef.String]
3+
34
(t: scala.quoted.Type[scala.Predef.String])
45
}

tests/run-with-compiler/quote-owners-2.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
val a: immutable.List[scala.Int] = {
55
type T = scala.List[scala.Int]
66
val b: T = scala.Nil.::[scala.Int](3)
7+
78
(b: collection.immutable.List[scala.Int])
89
}
10+
911
(a.head: scala.Int)
1012
}
13+
1114
(ff: scala.Int)
1215
}

tests/run-with-compiler/quote-owners.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
val a: scala.Int = 9
55
a.+(0)
66
}
7+
78
(ff: scala.Int)
89
}

tests/run-with-compiler/quote-unrolled-foreach.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
array.update(1, 2)
7070
array.update(2, 3)
7171
array.update(3, 4)
72+
7273
(array: scala.Array[scala.Int])
7374
}
7475

@@ -79,6 +80,7 @@
7980
array.update(1, 3)
8081
array.update(2, 4)
8182
array.update(3, 5)
83+
8284
(array: scala.Array[scala.Int])
8385
}
8486
val size: scala.Int = arr1.length

tests/run-with-compiler/shonan-hmm-simple.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Complex(4,3)
1313
sum = sum.+(arr1.apply(i).*(arr2.apply(i)))
1414
i = i.+(1)
1515
}
16+
1617
(sum: scala.Int)
1718
})
1819
10

tests/run-with-compiler/shonan-hmm.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ List(25, 30, 20, 43, 44)
2525
sum = sum.+(v.apply(i$2).*(a.apply(i).apply(i$2)))
2626
i$2 = i$2.+(1)
2727
}
28+
2829
(sum: scala.Int)
2930
})
3031
i = i.+(1)
@@ -232,6 +233,7 @@ List(25, 30, 20, 43, 44)
232233
sum = sum.+(v.apply(i).*(arr.apply(3).apply(i)))
233234
i = i.+(1)
234235
}
236+
235237
(sum: scala.Int)
236238
})
237239
vout.update(4, v.apply(2).*(3).+(v.apply(4).*(7)))
@@ -261,6 +263,7 @@ List(25, 30, 20, 43, 44)
261263
}.apply(i)))
262264
i = i.+(1)
263265
}
266+
264267
(sum: scala.Int)
265268
})
266269
vout.update(4, v.apply(2).*(3).+(v.apply(4).*(7)))
@@ -291,6 +294,7 @@ List(25, 30, 20, 43, 44)
291294
sum = sum.+(v.apply(i).*(row.apply(i)))
292295
i = i.+(1)
293296
}
297+
294298
(sum: scala.Int)
295299
})
296300
vout.update(4, v.apply(2).*(3).+(v.apply(4).*(7)))

tests/run/t4300.decompiled

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ object Test {
1717

1818
{
1919
final class $anon() extends b.C
20+
2021
(new $anon(): b.C)
2122
}.c()
2223
b.g()
2324
b.h()
2425
}
25-
}
26+
}

0 commit comments

Comments
 (0)