Skip to content

Fix #5001: add test #5999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
def AnonClass(parents: List[Type], fns: List[TermSymbol], methNames: List[TermName])(implicit ctx: Context): Block = {
val owner = fns.head.owner
val parents1 =
if (parents.head.classSymbol.is(Trait)) parents.head.parents.head :: parents
if (parents.head.classSymbol.is(Trait)) {
val head = parents.head.parents.head
if (head.isRef(defn.AnyClass)) defn.AnyRefType :: parents else head :: parents
}
else parents
val cls = ctx.newNormalizedClassSymbol(owner, tpnme.ANON_CLASS, Synthetic | Final, parents1,
coord = fns.map(_.span).reduceLeft(_ union _))
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ class Definitions {
arr
}

private def completeClass(cls: ClassSymbol): ClassSymbol = {
ensureConstructor(cls, EmptyScope)
private def completeClass(cls: ClassSymbol, ensureCtor: Boolean = true): ClassSymbol = {
if (ensureCtor) ensureConstructor(cls, EmptyScope)
if (cls.linkedClass.exists) cls.linkedClass.info = NoType
cls
}
Expand Down Expand Up @@ -262,7 +262,7 @@ class Definitions {
* def getClass: java.lang.Class[T] = ???
* }
*/
lazy val AnyClass: ClassSymbol = completeClass(enterCompleteClassSymbol(ScalaPackageClass, tpnme.Any, Abstract, Nil))
lazy val AnyClass: ClassSymbol = completeClass(enterCompleteClassSymbol(ScalaPackageClass, tpnme.Any, Abstract, Nil), ensureCtor = false)
def AnyType: TypeRef = AnyClass.typeRef
lazy val AnyValClass: ClassSymbol = completeClass(enterCompleteClassSymbol(ScalaPackageClass, tpnme.AnyVal, Abstract, List(AnyClass.typeRef)))
def AnyValType: TypeRef = AnyValClass.typeRef
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ class Typer extends Namer
case templ: untpd.Template =>
import untpd._
var templ1 = templ
def isEligible(tp: Type) = tp.exists && !tp.typeSymbol.is(Final)
def isEligible(tp: Type) = tp.exists && !tp.typeSymbol.is(Final) && !tp.isRef(defn.AnyClass)
if (templ1.parents.isEmpty &&
isFullyDefined(pt, ForceDegree.noBottom) &&
isEligible(pt.underlyingClassRef(refinementOK = false)))
Expand Down
1 change: 1 addition & 0 deletions library/src/scala/tasty/reflect/Printers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@ trait Printers
case Term.Select(qual, _) => rec(qual)
case Term.Apply(fn, _) => rec(fn)
case Term.TypeApply(fn, _) => rec(fn)
case Term.Typed(_, _) => this += doubleLineBreak()
case _ => this += lineBreak()
}
next match {
Expand Down
2 changes: 2 additions & 0 deletions tests/neg/i4820.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class Foo[A]
class Bar[A] extends Foo // error
5 changes: 5 additions & 0 deletions tests/neg/i4820b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
trait SetOps[A, +C <: SetOps[A, C]] {
def concat(that: Iterable[A]): C = ???
}

class Set1[A] extends SetOps // error: should be SetOps[A, Set1[A]]
2 changes: 2 additions & 0 deletions tests/neg/i4820c.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
trait Foo[A]
class Bar[A] extends Foo // error
1 change: 1 addition & 0 deletions tests/neg/i5001.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
case class i1() extends Any // error: Any does not have a constructor

This file was deleted.

4 changes: 3 additions & 1 deletion tests/pos/i0306.decompiled
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ object bar {
val y: scala.collection.Seq[_ >: scala.Nothing <: scala.Any] = bar.x match {
case x: bar.C[u] =>
def xx: u = xx

((xx: u): scala.collection.Seq[_ >: scala.Nothing <: scala.Any])
}
val z: java.lang.String = {
def xx: scala.Predef.String = xx

(xx: java.lang.String)
}
}
}
1 change: 1 addition & 0 deletions tests/pos/i5001.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
case class i1() extends AnyRef
3 changes: 2 additions & 1 deletion tests/pos/simpleRefinement.decompiled
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Foo() {
def w[T]: scala.Predef.String = "a"
def w2[T](a: scala.Null)(b: scala.Null): scala.Null = null
}

(new $anon(): Bar {
type S >: scala.Int <: scala.Int
type T >: scala.Function1[scala.Int, scala.Int] <: scala.Function1[scala.Int, scala.Int]
Expand All @@ -44,4 +45,4 @@ class Foo() {
def w2[T >: scala.Nothing <: scala.Any](a: scala.Null)(b: scala.Null): scala.Null
})
}
}
}
1 change: 1 addition & 0 deletions tests/run-with-compiler/i3876-c.check
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
val f: scala.Function1[scala.Int, scala.Int] {
def apply(x: scala.Int): scala.Int
} = ((x: scala.Int) => x.+(x))

(f: scala.Function1[scala.Int, scala.Int] {
def apply(x: scala.Int): scala.Int
}).apply(x$1)
Expand Down
1 change: 1 addition & 0 deletions tests/run-with-compiler/quote-nested-3.check
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
type T = scala.Predef.String
val x: java.lang.String = "foo"
val z: T = x

(x: java.lang.String)
}
1 change: 1 addition & 0 deletions tests/run-with-compiler/quote-nested-4.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
val t: scala.quoted.Type[scala.Predef.String] = scala.quoted.Type.apply[scala.Predef.String]

(t: scala.quoted.Type[scala.Predef.String])
}
3 changes: 3 additions & 0 deletions tests/run-with-compiler/quote-owners-2.check
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
val a: immutable.List[scala.Int] = {
type T = scala.List[scala.Int]
val b: T = scala.Nil.::[scala.Int](3)

(b: collection.immutable.List[scala.Int])
}

(a.head: scala.Int)
}

(ff: scala.Int)
}
1 change: 1 addition & 0 deletions tests/run-with-compiler/quote-owners.check
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
val a: scala.Int = 9
a.+(0)
}

(ff: scala.Int)
}
2 changes: 2 additions & 0 deletions tests/run-with-compiler/quote-unrolled-foreach.check
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
array.update(1, 2)
array.update(2, 3)
array.update(3, 4)

(array: scala.Array[scala.Int])
}

Expand All @@ -79,6 +80,7 @@
array.update(1, 3)
array.update(2, 4)
array.update(3, 5)

(array: scala.Array[scala.Int])
}
val size: scala.Int = arr1.length
Expand Down
1 change: 1 addition & 0 deletions tests/run-with-compiler/shonan-hmm-simple.check
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Complex(4,3)
sum = sum.+(arr1.apply(i).*(arr2.apply(i)))
i = i.+(1)
}

(sum: scala.Int)
})
10
Expand Down
4 changes: 4 additions & 0 deletions tests/run-with-compiler/shonan-hmm.check
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ List(25, 30, 20, 43, 44)
sum = sum.+(v.apply(i$2).*(a.apply(i).apply(i$2)))
i$2 = i$2.+(1)
}

(sum: scala.Int)
})
i = i.+(1)
Expand Down Expand Up @@ -232,6 +233,7 @@ List(25, 30, 20, 43, 44)
sum = sum.+(v.apply(i).*(arr.apply(3).apply(i)))
i = i.+(1)
}

(sum: scala.Int)
})
vout.update(4, v.apply(2).*(3).+(v.apply(4).*(7)))
Expand Down Expand Up @@ -261,6 +263,7 @@ List(25, 30, 20, 43, 44)
}.apply(i)))
i = i.+(1)
}

(sum: scala.Int)
})
vout.update(4, v.apply(2).*(3).+(v.apply(4).*(7)))
Expand Down Expand Up @@ -291,6 +294,7 @@ List(25, 30, 20, 43, 44)
sum = sum.+(v.apply(i).*(row.apply(i)))
i = i.+(1)
}

(sum: scala.Int)
})
vout.update(4, v.apply(2).*(3).+(v.apply(4).*(7)))
Expand Down
3 changes: 2 additions & 1 deletion tests/run/t4300.decompiled
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ object Test {

{
final class $anon() extends b.C

(new $anon(): b.C)
}.c()
b.g()
b.h()
}
}
}