Skip to content

Regression tests #14855

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 2 commits into from
Apr 6, 2022
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
51 changes: 51 additions & 0 deletions tests/neg-custom-args/allow-deep-subtypes/i5877.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
object Main {
def main(a: Array[String]): Unit = {
println("you may not run `testHasThisType` - just check that it compiles")
// comment lines after "// this line of code makes" comments to make it compilable again
testHasThisType()
testHasThisType2()
}

// ---- ---- ---- ----

trait HasThisType[PThis <: HasThisType[_ <: PThis]] {
this: PThis =>
type This = PThis

// inline // uncommenting `inline` cause problem in scastie dotty version, but is fixed in dotty `master`
def self(): This with this.type = this
}

// ---- ---- ---- ----

def testHasThisType(): Unit = {
def testSelf[PThis <: HasThisType[_ <: PThis]](that: HasThisType[PThis]): Unit = {
val thatSelf = that.self()
// that.self().type <: that.This
assert(implicitly[thatSelf.type <:< that.This] != null)
}
val that: HasThisType[_] = Foo() // null.asInstanceOf
testSelf(that) // error
}


def testHasThisType2(): Unit = {
def testSelf[PThis <: HasThisType[_ <: PThis]](that: PThis with HasThisType[PThis]): Unit = {
// that.type <: that.This
assert(implicitly[that.type <:< that.This] != null)
}
val that: HasThisType[_] = Foo() // null.asInstanceOf
// this line of code makes Dotty compiler infinite recursion (stopped only by overflow) - comment it to make it compilable again
testSelf(that) // error
}

// ---- ---- ---- ----

// `HasThisType` instantiation/sub-classing
trait FooLike[PThis <: FooLike[_ <: PThis]] extends HasThisType[PThis] {
this: PThis =>
}
case class Foo(payload: Any = "dummy") extends FooLike[Foo]
case class Bar(dummy: Any = "payload") extends FooLike[FooLike[_]]

}
6 changes: 6 additions & 0 deletions tests/neg/i6778.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- [E104] Syntax Error: tests/neg/i6778.scala:3:27 ---------------------------------------------------------------------
3 |class Bar extends Foo with A(10) // error
| ^^^^^
| class A is not a trait
|
| longer explanation available when compiling with `-explain`
3 changes: 3 additions & 0 deletions tests/neg/i6778.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trait Foo
class A(x: Int)
class Bar extends Foo with A(10) // error
93 changes: 93 additions & 0 deletions tests/pos/i5288.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
trait C { type M; val m: M }

object Test {
// Arity 1 ------------------------------------------------------------------

// Function1
def m1(i: Int): Int = 1
val f1Expected: Int => Int = m1
val f1Inferred = m1
identity[Int => Int](f1Inferred)

// ImplicitFunction1
def m4(using i: Int): Int = 4
val f4Expected: Int ?=> Int = m4
// val f4Inferred = m4 // can't work since no expected type
// identity[Int ?=> Int](f4Inferred)

// DependentFunction1
def m7(c: C): c.M = c.m
val f7Expected: (c: C) => c.M = m7
val f7Inferred = m7
identity[(c: C) => c.M](f7Inferred)

// Arity 2 ------------------------------------------------------------------

// Function2
def m2(i: Int, s: String): Int = 2
val f2Expected: (Int, String) => Int = m2
val f2Inferred = m2
identity[(Int, String) => Int](f2Inferred)

// ImplicitFunction2
def m5(using i: Int, s: String): Int = 5
val f5Expected: (Int, String) ?=> Int = m5
// val f5Inferred = m5 // can't work since no expected type
// identity[(Int, String) ?=> Int](f5Inferred)

// DependentFunction2
def m9(c1: C, c2: C): c1.M | c2.M = c1.m
val f9Expected: (c1: C, c2: C) => c1.M | c2.M = m9
val f9Inferred = m9
identity[(c1: C, c2: C) => c1.M | c2.M](f9Inferred)

// Function1[Function1]
def m8(i: Int)(s: String): Int = 8
val f8Expected: Int => String => Int = m8
val f8Inferred = m8
identity[Int => String => Int](f8Inferred)

// Function1[ImplicitFunction1]
def m6(i: Int)(using s: String): Int = 6
val f6Expected: Int => String ?=> Int = m6
//val f6Inferred = m6 // can't work since no expected type
//identity[Int => String ?=> Int](f6Inferred)

// Function1[DependentFunction1]
def mA(i: Int)(c: C): c.M = c.m
val fAExpected: Int => (c: C) => c.M = mA
val fAInferred = mA
identity[Int => (c: C) => c.M](fAInferred)

// ImplicitFunction1[ImplicitFunction1] -- Can't be expressed as a method...
// ImplicitFunction1[Function1] -- Can't be expressed as a method...
// ImplicitFunction1[DependentFunction1] -- Can't be expressed as a method...

// DependentFunction1[Function1]
def mB(c: C)(s: String): c.M = c.m
val fBExpected: (c: C) => String => c.M = mB
val fBInferred = mB
identity[(c: C) => String => c.M](fBInferred)

// DependentFunction1[ImplicitFunction1]
def mC(c: C)(using s: String): c.M = c.m
// val fCExpected: (c: C) => String ?=> c.M = mC
// gives:
// Implementation restriction: Expected result type (c: C) => (String) ?=> c.M
// is a curried dependent context function type. Such types are not yet supported.

// val fCInferred = mC // can't work since no expected type
// identity[(c: C) => String ?=> c.m](fCInferred)

// DependentFunction1[DependentFunction1]
def mD(c1: C)(c2: C): c1.M | c2.M = c1.m
val fDExpected: (c1: C) => (c2: C) => c1.M | c2.M = mD
val fDInferred = mD
identity[(c1: C) => (c2: C) => c1.M | c2.M](fDInferred)

// Missing from the above:
// - interactions with by name
// - interactions with default arguments
// - interactions with inline method
// - interactions with inline arguments
}
12 changes: 12 additions & 0 deletions tests/run/i7281.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

trait T {
case class X[A]()
}

object a extends T
object b extends T

val ax = a.X()
val bx = b.X()

@main def Test = assert(ax != bx)