diff --git a/tests/neg/empty-given.scala b/tests/neg/empty-given.scala new file mode 100644 index 000000000000..cf7566724cc2 --- /dev/null +++ b/tests/neg/empty-given.scala @@ -0,0 +1,3 @@ +given { + def foo = 1 // error +} \ No newline at end of file diff --git a/tests/pending/neg/i7445.scala b/tests/pending/neg/i7445.scala new file mode 100644 index 000000000000..88c2f04a5b3d --- /dev/null +++ b/tests/pending/neg/i7445.scala @@ -0,0 +1,8 @@ +object Main { + type O1[A] = { + type OutInner[X] = Unit + type Out = OutInner[A] + } + + def f1: O1[Int]#Out = ??? +} \ No newline at end of file diff --git a/tests/pending/pos/overload-generic.scala b/tests/pending/pos/overload-generic.scala new file mode 100644 index 000000000000..e5d951542e05 --- /dev/null +++ b/tests/pending/pos/overload-generic.scala @@ -0,0 +1,24 @@ +class Test { + def rawr(string: String): String = string +} + +implicit final class RawrExt(val t: Test) { + def rawr(int: Int): Int = int +} + +val t = new Test + +val r0 = t.rawr(5) + + +class TestP { + def rawr[A](list: List[A]): List[A] = list +} + +implicit final class RawrExtP(val t: TestP) { + def rawr(int: Int): Int = int +} + +val tt = new TestP + +val r1 = tt.rawr(5) // This doesn't compile \ No newline at end of file diff --git a/tests/pos/infer1.scala b/tests/pos/infer1.scala new file mode 100644 index 000000000000..3d1114c2d0a8 --- /dev/null +++ b/tests/pos/infer1.scala @@ -0,0 +1,30 @@ +trait TestInferrence[T] { + + def getInt(t: T): Int + +} + +object TestIntInferrence extends TestInferrence[Int] { + override def getInt(i: Int) = i +} + +object InferrenceTest { + + def createNumberHandler[T]( + testInfer: TestInferrence[T] = TestIntInferrence, + handlers: Map[String, T => Unit] = Map.empty, + ): T => Unit = { + + (t: T) => { + testInfer.getInt(t) + () + } + + } +} + +class InferrenceTest { + + val handler = InferrenceTest.createNumberHandler() + +} diff --git a/tests/run/Pouring.check b/tests/run/Pouring.check new file mode 100644 index 000000000000..f07f29105c0b --- /dev/null +++ b/tests/run/Pouring.check @@ -0,0 +1,2 @@ +Vector(Empty(0), Empty(1), Fill(0), Fill(1), Pour(0,1), Pour(1,0)) +Fill(1) Pour(1,0) Empty(0) Pour(1,0) Fill(1) Pour(1,0) --> Vector(4, 6) diff --git a/tests/run/Pouring.scala b/tests/run/Pouring.scala new file mode 100644 index 000000000000..b61d54bf1a3f --- /dev/null +++ b/tests/run/Pouring.scala @@ -0,0 +1,56 @@ +class Pouring(capacity: Vector[Int]) with + type Glass = Int + type Content = Vector[Int] + + enum Move with + def apply(content: Content): Content = this match + case Empty(g) => content.updated(g, 0) + case Fill(g) => content.updated(g, capacity(g)) + case Pour(from, to) => + val amount = content(from) min (capacity(to) - content(to)) + def (s: Content) adjust (g: Glass, delta: Int) = s.updated(g, s(g) + delta) + content.adjust(from, -amount).adjust(to, amount) + + case Empty(glass: Glass) + case Fill(glass: Glass) + case Pour(from: Glass, to: Glass) + end Move + + val moves = + val glasses = 0 until capacity.length + (for g <- glasses yield Move.Empty(g)) + ++ (for g <- glasses yield Move.Fill(g)) + ++ (for g1 <- glasses; g2 <- glasses if g1 != g2 yield Move.Pour(g1, g2)) + + class Path(history: List[Move], val endContent: Content) with + def extend(move: Move) = Path(move :: history, move(endContent)) + override def toString = s"${history.reverse.mkString(" ")} --> $endContent" + end Path + + val initialContent: Content = capacity.map(x => 0) + val initialPath = Path(Nil, initialContent) + + def from(paths: Set[Path], explored: Set[Content]): LazyList[Set[Path]] = + if paths.isEmpty then LazyList.empty + else + val extensions = + for + path <- paths + move <- moves + next = path.extend(move) + if !explored.contains(next.endContent) + yield next + paths #:: from(extensions, explored ++ extensions.map(_.endContent)) + + def solutions(target: Int): LazyList[Path] = + for + paths <- from(Set(initialPath), Set(initialContent)) + path <- paths + if path.endContent.contains(target) + yield path +end Pouring + +@main def Test = + val problem = Pouring(Vector(4, 7)) + println(problem.moves) + println(problem.solutions(6).head)