-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
nicolasstucki
merged 1 commit into
scala:master
from
dotty-staging:add-scala-days-2019-regression-tests
Jun 12, 2019
Merged
Add regression tests #6675
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/pos/scala-days-2019-slides/metaprogramming-1-forset.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
30
tests/pos/scala-days-2019-slides/metaprogramming-1-logger.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
tests/pos/scala-days-2019-slides/metaprogramming-1-match.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
72
tests/pos/scala-days-2019-slides/metaprogramming-1-power.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
// } | ||
|
||
} | ||
|
17 changes: 17 additions & 0 deletions
17
tests/pos/scala-days-2019-slides/metaprogramming-2-addEventListener.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
14
tests/pos/scala-days-2019-slides/metaprogramming-2-elem.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
tests/pos/scala-days-2019-slides/metaprogramming-2-tuple.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.