Skip to content

Add regression tests #6675

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
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
1 change: 1 addition & 0 deletions compiler/test/dotc/pos-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ t3249
t3486
t3612.scala
reference
scala-days-2019-slides
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it's added to blacklist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type matches that get printed different.


# type of super reference changes due to late addition of Mirror.Singleton
i939.scala
Expand Down
14 changes: 14 additions & 0 deletions tests/pos/scala-days-2019-slides/metaprogramming-1-forset.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
object ForSetExample {

import scala.collection.immutable._

inline def setFor[T]: Set[T] =
implicit match {
case ord: Ordering[T] => new TreeSet[T]
case _ => new HashSet[T]
}

setFor[String] // new TreeSet(scala.math.Ordering.String)
setFor[Object] // new HashSet

}
30 changes: 30 additions & 0 deletions tests/pos/scala-days-2019-slides/metaprogramming-1-logger.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
object Logger {

var indent = 0

inline def log[T](msg: String)(op: => T): T = {
println(s"${" " * indent}start $msg")
indent += 1
val result = op
indent -= 1
println(s"${" " * indent}$msg = $result")
result
}
}

object Logger2 {

private var indent = 0
// def inline$indent: Int = indent
// def inline$indent_=(x$0: Int): Unit = indent = x$0

inline def log[T](msg: String)(op: => T): T = {
println(s"${" " * indent}start $msg")
indent += 1 // inline$indent = inline$indent + 1

val result = op
indent -= 1 // inline$indent = inline$indent - 1
println(s"${" " * indent}$msg = $result")
result
}
}
14 changes: 14 additions & 0 deletions tests/pos/scala-days-2019-slides/metaprogramming-1-match.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
object App {

trait Nat
case object Zero extends Nat
case class Succ[N <: Nat](n: N) extends Nat

inline def toInt(n: => Nat): Int = inline n match {
case Zero => 0
case Succ(n1) => toInt(n1) + 1
}

val natTwo = toInt(Succ(Succ(Zero)))

}
72 changes: 72 additions & 0 deletions tests/pos/scala-days-2019-slides/metaprogramming-1-power.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
object App2 {

inline def power(x: Long, n: Int): Long = {
if (n == 0)
1L
else if (n % 2 == 1)
x * power(x, n - 1)
else {
val y: Long = x * x
power(y, n / 2)
}
}

val x: Long = 5L

power(x, 10)

// def badPower(x: Long, n: Int): Long = {
// power(x, n) // error: Maximal number of successive inlines (32) exceeded, Maybe this is caused by a recursive inline method?
// }

}

object App3 {

inline def power(x: Long, inline n: Int): Long = {
if (n == 0)
1L
else if (n % 2 == 1)
x * power(x, n - 1)
else {
val y: Long = x * x
power(y, n / 2)
}
}

val x: Long = 5L
val n: Int = 10

power(x, 10)

// def badPower(x: Long, n: Int): Long = {
// power(x, n) // error: argument to inline parameter must be a known value
// }

}


object App4 {

inline def power(x: Long, n: Int): Long = {
inline if (n == 0)
1L
else inline if (n % 2 == 1)
x * power(x, n - 1)
else {
val y: Long = x * x
power(y, n / 2)
}
}

val x: Long = 5L
val n: Int = 10

power(x, 10)

// def badPower(x: Long, n: Int): Long = {
// power(x, n) // error: cannot reduce inline if
// }

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
object JS {

object dom {
type Event
type MouseEvent <: Event
}

type EventTypeOf[Tp <: String] <: dom.Event = Tp match {
case "click" => dom.MouseEvent
case _ => dom.Event
}

def addEventListener[Tp <: String, Ev <: EventTypeOf[Tp]](tpe: Tp)(e: Ev => Any): Unit = ???

addEventListener("click") { (e: dom.MouseEvent) => ??? }

}
14 changes: 14 additions & 0 deletions tests/pos/scala-days-2019-slides/metaprogramming-2-elem.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
object ElemExample {

type Elem[X] = X match {
case String => Char
case Array[t] => t
case Iterable[t] => t
}


the[Elem[String] =:= Char]
the[Elem[Array[Int]] =:= Int]
the[Elem[List[Float]] =:= Float]
the[Elem[Nil.type] =:= Nothing]
}
13 changes: 13 additions & 0 deletions tests/pos/scala-days-2019-slides/metaprogramming-2-tuple.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
object TupleExample {
import Tuple._

type A
type B
type C

the[Concat[A *: B *: Unit, C *: Unit] =:= A *: B *: C *: Unit]

the[Concat[A *: B *: Unit, C *: Tuple] =:= A *: B *: C *: Tuple]

the[Concat[A *: B *: Tuple, C *: Unit] <:< A *: B *: Tuple]
}