diff options
author | Martin Odersky <odersky@gmail.com> | 2016-12-14 17:38:21 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-12-14 18:25:19 +0100 |
commit | 90ce8875c874f011b335390b3b41422793e1c7aa (patch) | |
tree | fae5c3e54ab92b8651122931035ddfd35f61e532 /tests/pos | |
parent | ba06bf06721f1a8de7d68d22ad7eba27fff90c43 (diff) | |
download | dotty-90ce8875c874f011b335390b3b41422793e1c7aa.tar.gz dotty-90ce8875c874f011b335390b3b41422793e1c7aa.tar.bz2 dotty-90ce8875c874f011b335390b3b41422793e1c7aa.zip |
More tests and other odds and end
- Add tests that work to pos/neg, tests that don't work yet to pending/pos/neg.
- Also, change .gitignore to allow for a local directory.
- Also add a draft page to the docs.
Diffstat (limited to 'tests/pos')
-rw-r--r-- | tests/pos/Monoid.scala | 61 | ||||
-rw-r--r-- | tests/pos/i1704.scala | 4 | ||||
-rw-r--r-- | tests/pos/i1777.scala | 9 |
3 files changed, 74 insertions, 0 deletions
diff --git a/tests/pos/Monoid.scala b/tests/pos/Monoid.scala new file mode 100644 index 000000000..f6004cdf3 --- /dev/null +++ b/tests/pos/Monoid.scala @@ -0,0 +1,61 @@ +package strawman.typeclasses + +trait SemiGroup[T] { + def append(x: T, y: T): T +} +object SemiGroup { + class Ops { + implicit class InfixAppend[T: SemiGroup](self: T) { + def |+| (other: T): T = implicitly[SemiGroup[T]].append(self, other) + } + } + object ops extends Ops +} + +trait Monoid[T] extends SemiGroup[T] { + val id: T +} +object Monoid { + object ops extends SemiGroup.Ops +} + +trait Ring[T] extends Monoid[T] { + val zero = id + val one: T + def product(x: T, y: T): T +} +object Ring { + class Ops extends SemiGroup.Ops { + implicit class InfixProduct[T: Ring](self: T) { + def |*| (other: T): T = implicitly[Ring[T]].product(self, other) + } + } + object ops extends Ops +} + + + +object Test { + implicit object StringMonoid extends Monoid[String] { + def append(x: String, y: String): String = x ++ y + val id = "" + } + + implicit object IntRing extends Ring[Int] { + def append(x: Int, y: Int) = x + y + val id = 0 + val one = 1 + def product(x: Int, y: Int) = x * y + } + + import Monoid.ops._ // works in dotty, fails in scalac + import Ring.ops._ + "abc" |+| "def" + "abc" |+| StringMonoid.id + StringMonoid.id |+| "abc" + + 1 |+| 2 + 3 |*| 3 + + +} diff --git a/tests/pos/i1704.scala b/tests/pos/i1704.scala new file mode 100644 index 000000000..94bc03c4d --- /dev/null +++ b/tests/pos/i1704.scala @@ -0,0 +1,4 @@ +trait AnyRef { + val StringMatch = new AnyRef {} + trait Something { (AnyRef) match { case (StringMatch) => } } +} diff --git a/tests/pos/i1777.scala b/tests/pos/i1777.scala new file mode 100644 index 000000000..381ff9139 --- /dev/null +++ b/tests/pos/i1777.scala @@ -0,0 +1,9 @@ +object Main extends App { + import scala.collection.immutable._ + case class Foo(s: String) + { + implicit val orderingS: Ordering[String] = Ordering[String] // Crash + val tree = TreeMap.empty ++ (1 to 100).map { i => Foo(i.toString) -> i } + println(tree.getClass) + } +} |