Skip to content

Commit 77992c9

Browse files
committed
Merge remote-tracking branch 'staging/add-semantic-names' into add-semantic-names
# Conflicts: # compiler/src/dotty/tools/dotc/core/SymDenotations.scala
2 parents 1058278 + 5bada41 commit 77992c9

19 files changed

+252
-0
lines changed

tests/pending/neg/i1846.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Bug {
2+
final val x = 42
3+
val y = x
4+
x match {case y.toString => 42 case y => 42}
5+
}

tests/pending/neg/i1905.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Arr[T](val underlying: scala.Array[T]) extends AnyVal {
2+
def foo = underlying
3+
}
4+
5+
abstract class SeqMonoTransforms[+A, +Repr] {
6+
protected[this] def fromIterableWithSameElemType(): Repr
7+
def getFIWSET: Repr = fromIterableWithSameElemType
8+
}
9+
10+
class ArrOps[A](val xs: Arr[A]) extends SeqMonoTransforms[A, Arr[A]] {
11+
def fromIterableWithSameElemType(): Arr[A] = xs
12+
}
13+
14+
object Test {
15+
def main(args: Array[String]) = {
16+
val arr = new Arr(Array(1, 2, 3))
17+
val t = new ArrOps(arr)
18+
val t2 = t.getFIWSET
19+
val x = arr.foo
20+
}
21+
}

tests/pending/neg/i2104.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
case class Pair[A, B](_1: A, _2: B)
2+
3+
trait Cons[+H, +T]
4+
5+
object Cons {
6+
def apply[H, T](h: H, t: T): Cons[H, T] = ???
7+
def unapply[H, T](t: Cons[H, T]): Option[Pair[H, T]] = ???
8+
}
9+
10+
object Test {
11+
def main(args: Array[String]): Unit = {
12+
Cons(Option(1), None) match {
13+
case Cons(Some(i), None) =>
14+
i: Int // error: found: Any(i), requires: Int
15+
assert(i == 1)
16+
}
17+
}
18+
}

tests/pending/neg/match.scala

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
object Test {
2+
3+
class Seq[T]
4+
class List[T] extends Seq[T] { def head: T = ??? }
5+
6+
val ss: Seq[Int] = ???
7+
ss match {
8+
case ss: List[int] =>
9+
val x = ss.head
10+
val y: Int = x
11+
}
12+
}
13+
object Test1 {
14+
15+
class Seq[T]
16+
class List[T] extends Seq[T] { def head: T = ??? }
17+
18+
val ss: Seq[Int] = ???
19+
ss match {
20+
case ss: List[Int] =>
21+
println(ss)
22+
}
23+
}
24+
object Test2 {
25+
26+
trait A
27+
trait B
28+
val x: A & B = ???
29+
30+
(x: A) match {
31+
case x: B =>
32+
}
33+
}

tests/pending/pos/TypeIndexing.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// works in neither scalac nor dotty, but maybe could be made to work?
2+
trait A {
3+
type T
4+
val t : T
5+
}
6+
7+
object A {
8+
def unapply(arg: A): Option[arg.T] = Some(arg.t)
9+
}
10+
11+
object Test {
12+
def use(a : A) = a match {
13+
case b @ A(t)
14+
val s: b.T = t // type mismatch.
15+
// found t.type (with underlying type <unapply-selector>.T)
16+
// required: a.T
17+
}
18+
}

tests/pending/pos/i1793.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
import scala.ref.WeakReference
3+
def unapply[T <: AnyRef](wr: WeakReference[T]): Option[T] = {
4+
val x = wr.underlying.get
5+
if (x != null) Some(x) else None
6+
}
7+
}

tests/pending/pos/i1960.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
case class CC2[A, B](_1: A, _2: B)
2+
3+
object Test {
4+
def main(args: Array[String]): Unit = {
5+
val CC2(_, CC2(a, _)) = CC2(0, CC2(1, 2))
6+
assert(a == 1)
7+
}
8+
}

tests/pending/pos/i2032.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class foo(annotation: Any) // annotation.StaticAnnotation
2+
@foo(new AnyRef {}) trait A

tests/pending/pos/i2071.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
type PF[A, B] = PartialFunction[A, B]
3+
4+
val f: PF[Int, String] = {
5+
case i => "bar"
6+
}
7+
}

tests/pending/pos/i2201a.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Foo[T]
2+
3+
class Fix[F[_]](unfix: F[Fix[F]])
4+
object DocTree {
5+
type Const[T] = Foo[Int]
6+
type FixConst = Fix[Const]
7+
def docTree(s: Const[FixConst]): FixConst = new Fix(s)
8+
}

tests/pending/pos/i2201b.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
trait X
2+
trait Y
3+
4+
object Test {
5+
type One[A <: X, B <: Y]
6+
7+
type Two[TA <: Y, TB <: X] = One[TB, TA]
8+
9+
def foo[M[_ <: Y, _ <: X]](x: M[_ <: Y, _ <: X]) = x
10+
11+
val a: Two[Y, X] = ???
12+
13+
foo(a)
14+
}

tests/pending/pos/i2201c.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object Test {
2+
implicit val theAnswer: Int = 42
3+
4+
type Swap[A, B] = (B, A)
5+
6+
def foo[M[_, _], T, S](x: M[T, S])(implicit ev: T) = ev
7+
8+
val a: Swap[Int, String] = ("hi", 1)
9+
10+
foo(a)
11+
}

tests/pending/pos/match.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
3+
val ss: Seq[Int] = ???
4+
ss match {
5+
case ss: List[Int] => ???
6+
}
7+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Test {
2+
3+
def f[X, Y](x: X, y: Y): Int = ???
4+
5+
f[Int, String](1, "")
6+
f[X = Int, Y = String](1, "")
7+
f[X = Int](1, "")
8+
f[Y = String](1, "")
9+
}

tests/pending/pos/t9844.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
trait X[T <: X[T]] { self: T => }
2+
object Y extends X[Y.type]

tests/pending/run/i2072.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
trait T { lazy val x: String = "foo" }
2+
trait U { def x: Any }
3+
abstract class AC extends T with U // { def x: Any }
4+
5+
abstract class B { def x: Any }
6+
class C extends B { def x: String = "abc" }
7+
8+
package p2 {
9+
trait T1 { def f: Any }
10+
trait T2 extends T1 { def f: Number = ??? }
11+
trait T3 extends T1 { override def f: Integer = ??? }
12+
class C extends T2 with T3
13+
}
14+
15+
package p3 {
16+
17+
trait A { def f: Any }
18+
trait B extends A { def f: String }
19+
class C extends B { def f = "abc" }
20+
21+
}

tests/pending/run/nestedEq.scala

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
class Outer {
2+
3+
case class Inner()
4+
case class Inner2()
5+
6+
val inner: Inner = new Inner
7+
val inner2 = new Inner2
8+
9+
def checkInstance(o: Outer) =
10+
o.inner.isInstanceOf[this.Inner]
11+
12+
def checkPattern1(i: Any) =
13+
i match {
14+
case _: Inner => true
15+
case _ => false
16+
}
17+
18+
def checkPattern2(i: Any) =
19+
i match {
20+
case Inner() => true
21+
case _ => false
22+
}
23+
24+
def checkEquals(o: Outer) =
25+
o.inner == inner
26+
27+
}
28+
29+
object Test {
30+
31+
def main(args: Array[String]) = {
32+
val o1 = new Outer
33+
val o2 = new Outer
34+
println(o1.inner.hashCode)
35+
println(o2.inner.hashCode)
36+
println(o2.inner2.hashCode)
37+
assert(o1.checkInstance(o2))
38+
assert(!o1.checkPattern1(o2.inner))
39+
assert(!o1.checkPattern2(o2.inner))
40+
assert(!o1.checkEquals(o2))
41+
}
42+
43+
}

tests/pos/i2081.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
trait Foo {
2+
// This should not generate a $init method.
3+
// Currently this needs to be verified by manual inspection of the bytecode.
4+
def meth(x: Int): Int
5+
}
6+
trait Bar extends Foo
7+
trait Bam
8+
9+
class C extends Foo with Bar {
10+
def meth(x: Int) = x
11+
}

tests/pos/i2152.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Contra[-D](task: AnyRef)
2+
object Test {
3+
def narrow(task: AnyRef): Contra[task.type] = new Contra(task)
4+
def ident[Before](elems: Contra[Before]): Contra[Before] = elems
5+
val foo = null
6+
ident(narrow(foo))
7+
}

0 commit comments

Comments
 (0)