Skip to content

Commit

Permalink
Update most tests to new syntax
Browse files Browse the repository at this point in the history
I left some tests to use the old syntax, just so that we have early warnings for possible regressions. But most tests are now using the new syntax, so that we best reassurance that corner cases work.
  • Loading branch information
odersky committed Sep 30, 2024
1 parent 0c721dc commit 3a44cf8
Show file tree
Hide file tree
Showing 239 changed files with 1,135 additions and 468 deletions.
684 changes: 684 additions & 0 deletions docs/_docs/reference/contextual/sip-64.md

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions tests/init/crash/i6914.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object test1 {
class ToExpr[T](using Liftable[T]) extends Conversion[T, Expr[T]] {
def apply(x: T): Expr[T] = ???
}
given toExprFun[T](using Liftable[T]): ToExpr[T] with {}
given toExprFun: [T] => Liftable[T] => ToExpr[T]()

given Liftable[Int] = ???
given Liftable[String] = ???
Expand All @@ -16,14 +16,12 @@ object test1 {
def a: Expr[String] = "abc"
}

object test2 {
object test2:

given autoToExpr[T](using Liftable[T]): Conversion[T, Expr[T]] with {
given autoToExpr: [T] => Liftable[T] => Conversion[T, Expr[T]]:
def apply(x: T): Expr[T] = ???
}

given Liftable[Int] = ???
given Liftable[String] = ???

def a: Expr[String] = "abc"
}
6 changes: 2 additions & 4 deletions tests/init/crash/i7821.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ object XObject {

def anX: X = 5

given ops: Object with {
given ops: Object:
extension (x: X) def + (y: X): X = x + y
}
}

object MyXObject {
opaque type MyX = XObject.X

def anX: MyX = XObject.anX

given ops: Object with {
given ops: Object:
extension (x: MyX) def + (y: MyX): MyX = x + y // error: warring: Infinite recursive call
}
}

object Main extends App {
Expand Down
4 changes: 2 additions & 2 deletions tests/neg-macros/BigFloat/BigFloat_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ object BigFloat extends App {
def fromDigits(digits: String) = apply(digits)
}

given BigFloatFromDigits with {
given BigFloatFromDigits {
override inline def fromDigits(digits: String) = ${
BigFloatFromDigitsImpl('digits)
}
}

// Should be in StdLib:

given ToExpr[BigInt] with {
given ToExpr[BigInt] {
def apply(x: BigInt)(using Quotes) =
'{BigInt(${Expr(x.toString)})}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/GenericNumLits/Even_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object Even {
def fromDigits(digits: String) = evenFromDigits(digits)
}

given EvenFromDigits with {
given EvenFromDigits {
override transparent inline def fromDigits(digits: String) = ${
EvenFromDigitsImpl('digits)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/i11483/Test_2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package x
import scala.language.implicitConversions
import scala.concurrent.Future

given FutureAsyncMonad: CpsMonad[Future] with
given FutureAsyncMonad: CpsMonad[Future]:
def pure[T](t:T): Future[T] = ???
def impure[T](t:Future[T]): T = ???
def map[A,B](x:Future[A])(f: A=>B): Future[B] = ???
Expand Down
4 changes: 2 additions & 2 deletions tests/neg-macros/i17152/DFBits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ trait Baz
trait Width[T]:
type Out <: Int
object Width:
given fromDFBoolOrBit[T <: DFBoolOrBit]: Width[T] with
given fromDFBoolOrBit: [T <: DFBoolOrBit] => Width[T]:
type Out = 1
transparent inline given [T]: Width[T] = ${ getWidthMacro[T] }
def getWidthMacro[T](using Quotes, Type[T]): Expr[Width[T]] =
Expand All @@ -38,7 +38,7 @@ private object CompanionsDFBits:
type OutW <: Int
def apply(value: R): DFValOf[DFBits[OutW]]
object Candidate:
given fromDFUInt[W <: Int, R <: DFValOf[DFDecimal]]: Candidate[R] with
given fromDFUInt: [W <: Int, R <: DFValOf[DFDecimal]] => Candidate[R]:
type OutW = W
def apply(value: R): DFValOf[DFBits[W]] =
import DFVal.Ops.bits
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/i19601/Macro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object Macros {
'{ () }

}
given [A](using Type[A]): FromExpr[Assertion[A]] with {
given [A] => Type[A] => FromExpr[Assertion[A]] {
def unapply(assertion: Expr[Assertion[A]])(using Quotes): Option[Assertion[A]] = {
import quotes.reflect.*

Expand Down
6 changes: 3 additions & 3 deletions tests/neg-macros/i7919.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import scala.quoted.*
object Test {
def staged[T](using Quotes) = {
import quotes.reflect.*
given typeT: Type[T] with {} // error
given typeT: Type[T] {} // error
val tt = TypeRepr.of[T]
'{ "in staged" }
}

given Expr[Int] with {} // error
given Expr[Int] {} // error
new Expr[Int] // error
class Expr2 extends Expr[Int] // error

given Type[Int] with {} // error
given Type[Int] {} // error
new Type[Int] // error
class Type2 extends Type[Int] // error

Expand Down
2 changes: 1 addition & 1 deletion tests/neg-with-compiler/GenericNumLits/Even_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object Even {
def fromDigits(digits: String) = evenFromDigits(digits)
}

given EvenFromDigits with {
given EvenFromDigits {
override inline def fromDigits(digits: String) = ${
EvenFromDigitsImpl('digits)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/17579.check
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
|
| longer explanation available when compiling with `-explain`
-- [E147] Syntax Warning: tests/neg/17579.scala:19:6 -------------------------------------------------------------------
19 | final given Object with {} // warning: modifier `final` is redundant for this definition
19 | final given Object() // warning: modifier `final` is redundant for this definition
| ^^^^^
| Modifier final is redundant for this definition
2 changes: 1 addition & 1 deletion tests/neg/17579.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class C:
{
// No error in this case, because the `given` is translated to a class
// definition, for which `final` is redundant but not illegal.
final given Object with {} // warning: modifier `final` is redundant for this definition
final given Object() // warning: modifier `final` is redundant for this definition
}

{
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/19414.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Printer
given Writer[JsValue] = ???
given Writer[JsObject] = ???

given [B: Writer](using printer: Printer = new Printer): BodySerializer[B] = ???
given [B: Writer] => (printer: Printer = new Printer) => BodySerializer[B] = ???

def f: Unit =
summon[BodySerializer[JsObject]] // error: Ambiguous given instances
2 changes: 1 addition & 1 deletion tests/neg/21538.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
trait Bar[T]
given [T]: Bar[T] with {}
given [T] => Bar[T]()
inline def foo[V](inline value: V)(using Bar[value.type]) : Unit = {} // error
2 changes: 1 addition & 1 deletion tests/neg/abstract-givens.check
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Error: tests/neg/abstract-givens.scala:11:8 -------------------------------------------------------------------------
11 | given s[T](using T): Seq[T] with // error
11 | given s: [T] => T => Seq[T]: // error
| ^
|instance cannot be created, since def iterator: Iterator[A] in trait IterableOnce in package scala.collection is not defined
-- [E164] Declaration Error: tests/neg/abstract-givens.scala:8:8 -------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/abstract-givens.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object Test extends T:
given y(using Int): String = summon[Int].toString * 22 // error
given z[T](using T): Seq[T] = List(summon[T]) // error

given s[T](using T): Seq[T] with // error
given s: [T] => T => Seq[T]: // error
def apply(x: Int) = ???
override def length = ???

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/eql.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
object lst:
opaque type Lst[+T] = Any
object Lst:
given lstCanEqual[T, U]: CanEqual[Lst[T], Lst[U]] = CanEqual.derived
given lstCanEqual: [T, U] => CanEqual[Lst[T], Lst[U]] = CanEqual.derived
val Empty: Lst[Nothing] = ???
end lst

Expand Down
2 changes: 1 addition & 1 deletion tests/neg/exports.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
type PrinterType
def print(bits: BitMap): Unit = ???
def status: List[String] = ???
given bitmap: BitMap with {}
given bitmap: BitMap()
}

class Scanner {
Expand Down
19 changes: 9 additions & 10 deletions tests/neg/extmethod-overload.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
object Test {
given a: AnyRef with
extension (x: Int) {
object Test:

given a: AnyRef:
extension (x: Int)
def |+| (y: Int) = x + y
}
given b: AnyRef with
extension (x: Int) {

given b: AnyRef:
extension (x: Int)
def |+| (y: String) = x + y.length
}

assert((1 |+| 2) == 3) // error ambiguous

locally {
locally:
import b.|+|
assert((1 |+| "2") == 2) // OK
}
}
2 changes: 1 addition & 1 deletion tests/neg/gadt-approximation-interaction.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object GivenLookup {

class Tag[T]

given ti: Tag[Int] with {}
given ti: Tag[Int]()

def foo[T](t: T, ev: T SUB Int) =
ev match { case SUB.Refl() =>
Expand Down
6 changes: 2 additions & 4 deletions tests/neg/genericNumbers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ object Test extends App {

case class Even(n: Int)

given FromDigits[Even] with {
def fromDigits(digits: String): Even = {
given FromDigits[Even]:
def fromDigits(digits: String): Even =
val intValue = digits.toInt
if (intValue % 2 == 0) Even(intValue)
else throw FromDigits.MalformedNumber()
}
}

val e: Even = 1234 // error

Expand Down
4 changes: 2 additions & 2 deletions tests/neg/given-loop-prevention.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
class Foo

object Bar {
given Foo with {}
given Foo()
given List[Foo] = List(summon[Foo]) // ok
}

object Baz {
given List[Foo] = List(summon[Foo]) // error
given Foo with {}
given Foo()
}
2 changes: 1 addition & 1 deletion tests/neg/i10901.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object BugExp4Point2D {
class C

object Container:
given C with {}
given C()

object Test:
extension (x: String)(using C)
Expand Down
4 changes: 1 addition & 3 deletions tests/neg/i11985.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ object Test {
def get(t: TT): C
}

given [T <: Tuple, C, EV <: TupleTypeIndex[T, C]]: TupleExtractor[T, C] with {
given [T <: Tuple, C, EV <: TupleTypeIndex[T, C]] => TupleExtractor[T, C]:
def get(t: T): C = t.toArray.apply(toIntC[TupleTypeIndex[T, C]]).asInstanceOf[C] // error
}


transparent inline def toIntC[N <: Int]: Int =
inline constValue[N] match
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i14177a.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import scala.compiletime.*

trait C[A]

inline given [Tup <: Tuple]: C[Tup] with
inline given [Tup <: Tuple] => C[Tup]:
val cs = summonAll[Tuple.Map[Tup, C]] // error: Tuple element types must be known at compile time
2 changes: 1 addition & 1 deletion tests/neg/i15474b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import scala.language.implicitConversions

object Test1:
given c: Conversion[ String, Int ] with
given c: Conversion[ String, Int ]:
def apply(from: String): Int = from.toInt // warn: infinite loop in function body
// nopos-error: No warnings can be incurred under -Werror (or -Xfatal-warnings)
2 changes: 1 addition & 1 deletion tests/neg/i16453.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def testScala3() = {
given Conversion[Char, String] = ???
given Conversion[Char, Option[Int]] = ???

given foo: Foo with
given foo: Foo:
type T = Int
given bar3: Int = 0
given baz3: Char = 'a'
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i19328conversion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ object i19328conversion:

type Id[A] = A

given wrapId[A]: Conversion[A, Id[A]] with
given wrapId: [A] => Conversion[A, Id[A]]:
def apply(x: A): Id[A] = x

def bar(using bool: Boolean): Unit = ()
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/i5978.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ opaque type Position[Buffer] = Int
trait TokenParser[Token, R]

object TextParser {
given TP: TokenParser[Char, Position[CharSequence]] with {}
given TP: TokenParser[Char, Position[CharSequence]]()

given FromCharToken(using T: TokenParser[Char, Position[CharSequence]])
: Conversion[Char, Position[CharSequence]] = ???
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/i6716.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class Foo

object Bar {
given Foo with {}
given Foo()
given List[Foo] = List(summon[Foo]) // ok
}

object Baz {
@annotation.nowarn
given List[Foo] = List(summon[Foo]) // error
given Foo with {}
given Foo()
}
2 changes: 1 addition & 1 deletion tests/neg/i7459.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait Eq[T] {
}

object Eq {
given Eq[Int] with {
given Eq[Int] {
def eqv(x: Int, y: Int) = x == y
}

Expand Down
3 changes: 1 addition & 2 deletions tests/neg/i8896-a.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ trait Foo[A]

object Example {

given Foo[Int] with {
}
given Foo[Int]()

def foo0[A: Foo]: A => A = identity
def foo1[A](implicit foo: Foo[A]): A => A = identity
Expand Down
3 changes: 1 addition & 2 deletions tests/neg/i8896-b.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ trait Foo[A]

object Example {

given Foo[Int] with {
}
given Foo[Int]()

def foo0[A: Foo]: A => A = identity
def foo1[A](implicit foo: Foo[A]): A => A = identity
Expand Down
4 changes: 2 additions & 2 deletions tests/neg/i9185.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
trait M[F[_]] { def pure[A](x: A): F[A] }
object M {
extension [A, F[A]](x: A) def pure(using m: M[F]): F[A] = m.pure(x)
given listMonad: M[List] with { def pure[A](x: A): List[A] = List(x) }
given optionMonad: M[Option] with { def pure[A](x: A): Option[A] = Some(x) }
given listMonad: M[List] { def pure[A](x: A): List[A] = List(x) }
given optionMonad: M[Option] { def pure[A](x: A): Option[A] = Some(x) }
val value1: List[String] = "ola".pure
val value2 = "ola".pure // error
val value3 = M.pure("ola") // error
Expand Down
Loading

0 comments on commit 3a44cf8

Please sign in to comment.