From 1d4db7fd65a1376ce71086a1a7fc5c524ee3a233 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Fri, 11 Oct 2024 16:23:06 -0700 Subject: [PATCH] Regression tests --- tests/pos/i17631.scala | 14 ++++++++++++++ tests/pos/i18366.scala | 15 ++++++++++++--- tests/warn/i17371.scala | 28 ++++++++++++++++++++++++++++ tests/warn/i18313.scala | 14 ++++++++++++++ 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 tests/warn/i17371.scala create mode 100644 tests/warn/i18313.scala diff --git a/tests/pos/i17631.scala b/tests/pos/i17631.scala index 0ede23dd5524..ddcb71354968 100644 --- a/tests/pos/i17631.scala +++ b/tests/pos/i17631.scala @@ -38,3 +38,17 @@ def `i18388`: Unit = val _ = pred () val _ = func + +trait L[T]: + type E + +def `i19748` = + type Warn1 = [T] => (l: L[T]) => T => l.E + type Warn2 = [T] => L[T] => T + type Warn3 = [T] => T => T + def use(x: (Warn1, Warn2, Warn3)) = x + use + +type NoWarning1 = [T] => (l: L[T]) => T => l.E +type NoWarning2 = [T] => L[T] => T +type NoWarning3 = [T] => T => T diff --git a/tests/pos/i18366.scala b/tests/pos/i18366.scala index 698510ad13a2..b6385b5bbb59 100644 --- a/tests/pos/i18366.scala +++ b/tests/pos/i18366.scala @@ -1,10 +1,19 @@ -//> using options -Xfatal-warnings -Wunused:all +//> using options -Werror -Wunused:all trait Builder { def foo(): Unit } -def repro = +def `i18366` = val builder: Builder = ??? import builder.{foo => bar} - bar() \ No newline at end of file + bar() + +import java.io.DataOutputStream + +val buffer: DataOutputStream = ??? + +import buffer.{write => put} + +def `i17315` = + put(0: Byte) diff --git a/tests/warn/i17371.scala b/tests/warn/i17371.scala new file mode 100644 index 000000000000..9e1c26368b8f --- /dev/null +++ b/tests/warn/i17371.scala @@ -0,0 +1,28 @@ +//> using options -Wunused:all + +class A +class B + +def Test() = + val ordA: Ordering[A] = ??? + val ordB: Ordering[B] = ??? + val a: A = ??? + val b: B = ??? + + import ordA.given + val _ = a > a + + import ordB.given + val _ = b < b + +// unminimized OP +trait Circular[T] extends Ordering[T] +trait Turns[C: Circular, T] extends Ordering[T]: + extension (turns: T) def extract: C + +def f[K, T](start: T, end: T)(using circular: Circular[K], turns: Turns[K, T]): Boolean = + import turns.given + if start > end then throw new IllegalArgumentException("start must be <= end") + + import circular.given + start.extract < end.extract diff --git a/tests/warn/i18313.scala b/tests/warn/i18313.scala new file mode 100644 index 000000000000..967985853fcf --- /dev/null +++ b/tests/warn/i18313.scala @@ -0,0 +1,14 @@ +//> using options -Wunused:imports + +import scala.deriving.Mirror + +case class Test(i: Int, d: Double) +case class Decoder(d: Product => Test) + +// OK, no warning returned +//val ok = Decoder(summon[Mirror.Of[Test]].fromProduct) +// +// returns warning: +// [warn] unused import +// [warn] import scala.deriving.Mirror +val d = Decoder(d = summon[Mirror.Of[Test]].fromProduct) // no warn