From 5d5ce1a80ea885b2905624a2fb7e48b3a88d3da4 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 22 Jan 2024 16:58:34 +0100 Subject: [PATCH] Add tests for context bounds migration Improves tests of #19316 --- tests/neg/context-bounds-migration-3.5.check | 6 ++++++ tests/neg/context-bounds-migration-3.5.scala | 10 ++++++++++ tests/neg/context-bounds-migration-future.check | 6 ++++++ tests/neg/context-bounds-migration-future.scala | 10 ++++++++++ tests/warn/context-bounds-migration-3.4.check | 6 ++++++ ...ration.scala => context-bounds-migration-3.4.scala} | 0 6 files changed, 38 insertions(+) create mode 100644 tests/neg/context-bounds-migration-3.5.check create mode 100644 tests/neg/context-bounds-migration-3.5.scala create mode 100644 tests/neg/context-bounds-migration-future.check create mode 100644 tests/neg/context-bounds-migration-future.scala create mode 100644 tests/warn/context-bounds-migration-3.4.check rename tests/warn/{context-bounds-migration.scala => context-bounds-migration-3.4.scala} (100%) diff --git a/tests/neg/context-bounds-migration-3.5.check b/tests/neg/context-bounds-migration-3.5.check new file mode 100644 index 000000000000..dd8a2aeefbf3 --- /dev/null +++ b/tests/neg/context-bounds-migration-3.5.check @@ -0,0 +1,6 @@ +-- Error: tests/neg/context-bounds-migration-3.5.scala:9:2 ------------------------------------------------------------- +9 | foo(C[Int]()) // error + | ^^^ + | Context bounds will map to context parameters. + | A `using` clause is needed to pass explicit arguments to them. + | This code can be rewritten automatically under -rewrite -source 3.4-migration. diff --git a/tests/neg/context-bounds-migration-3.5.scala b/tests/neg/context-bounds-migration-3.5.scala new file mode 100644 index 000000000000..e5c571d0e22e --- /dev/null +++ b/tests/neg/context-bounds-migration-3.5.scala @@ -0,0 +1,10 @@ +//> using options -source 3.5 + +class C[T] +def foo[X: C] = () + +given [T]: C[T] = C[T]() + +def Test = + foo(C[Int]()) // error + foo(using C[Int]()) // ok diff --git a/tests/neg/context-bounds-migration-future.check b/tests/neg/context-bounds-migration-future.check new file mode 100644 index 000000000000..f56da5d6b28d --- /dev/null +++ b/tests/neg/context-bounds-migration-future.check @@ -0,0 +1,6 @@ +-- [E050] Type Error: tests/neg/context-bounds-migration-future.scala:9:2 ---------------------------------------------- +9 | foo(C[Int]()) // error + | ^^^ + | method foo does not take more parameters + | + | longer explanation available when compiling with `-explain` diff --git a/tests/neg/context-bounds-migration-future.scala b/tests/neg/context-bounds-migration-future.scala new file mode 100644 index 000000000000..6d0e94c0b434 --- /dev/null +++ b/tests/neg/context-bounds-migration-future.scala @@ -0,0 +1,10 @@ +//> using options -source future + +class C[T] +def foo[X: C] = () + +given [T]: C[T] = C[T]() + +def Test = + foo(C[Int]()) // error + foo(using C[Int]()) // ok diff --git a/tests/warn/context-bounds-migration-3.4.check b/tests/warn/context-bounds-migration-3.4.check new file mode 100644 index 000000000000..5341cfbe3ea5 --- /dev/null +++ b/tests/warn/context-bounds-migration-3.4.check @@ -0,0 +1,6 @@ +-- Warning: tests/warn/context-bounds-migration-3.4.scala:9:2 ---------------------------------------------------------- +9 | foo(C[Int]()) // warn + | ^^^ + | Context bounds will map to context parameters. + | A `using` clause is needed to pass explicit arguments to them. + | This code can be rewritten automatically under -rewrite -source 3.4-migration. diff --git a/tests/warn/context-bounds-migration.scala b/tests/warn/context-bounds-migration-3.4.scala similarity index 100% rename from tests/warn/context-bounds-migration.scala rename to tests/warn/context-bounds-migration-3.4.scala