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+
}

0 commit comments

Comments
 (0)