Skip to content

Commit

Permalink
Swap two givens in Specs2 to satisfy new restriuction
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Dec 19, 2023
1 parent 07c821a commit 87e45fa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 30 deletions.
50 changes: 25 additions & 25 deletions tests/neg/i7294-a.check
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
-- [E007] Type Mismatch Error: tests/neg/i7294-a.scala:8:18 ------------------------------------------------------------
8 | case x: T => x.g(10) // error // error
| ^^^^^^^
| Found: Any
| Required: T
|
| where: T is a type in given instance f with bounds <: foo.Foo
|
| longer explanation available when compiling with `-explain`
-- Error: tests/neg/i7294-a.scala:8:10 ---------------------------------------------------------------------------------
8 | case x: T => x.g(10) // error // error
| ^
| Result of implicit search for scala.reflect.TypeTest[Nothing, T] will change.
| Current result foo.i7294-a$package.f will be no longer eligible
| because it is not defined before the search position.
| Result with new rules: No Matching Implicit.
| To opt into the new rules, use the `experimental.givenLoopPrevention` language import.
|
| To fix the problem without the language import, you could try one of the following:
| - use a `given ... with` clause as the enclosing given,
| - rearrange definitions so that foo.i7294-a$package.f comes earlier,
| - use an explicit argument.
| This will be an error in Scala 3.5 and later.
|
| where: T is a type in given instance f with bounds <: foo.Foo
-- [E007] Type Mismatch Error: tests/neg/i7294-a.scala:10:20 -----------------------------------------------------------
10 | case x: T => x.g(10) // error // error
| ^^^^^^^
| Found: Any
| Required: T
|
| where: T is a type in given instance f with bounds <: foo.Foo
|
| longer explanation available when compiling with `-explain`
-- Error: tests/neg/i7294-a.scala:10:12 --------------------------------------------------------------------------------
10 | case x: T => x.g(10) // error // error
| ^
| Result of implicit search for scala.reflect.TypeTest[Nothing, T] will change.
| Current result foo.Test.f will be no longer eligible
| because it is not defined before the search position.
| Result with new rules: No Matching Implicit.
| To opt into the new rules, use the `experimental.givenLoopPrevention` language import.
|
| To fix the problem without the language import, you could try one of the following:
| - use a `given ... with` clause as the enclosing given,
| - rearrange definitions so that foo.Test.f comes earlier,
| - use an explicit argument.
| This will be an error in Scala 3.5 and later.
|
| where: T is a type in given instance f with bounds <: foo.Foo
10 changes: 6 additions & 4 deletions tests/neg/i7294-a.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ package foo

trait Foo { def g(x: Int): Any }

inline given f[T <: Foo]: T = ??? match {
case x: T => x.g(10) // error // error
}
object Test:

@main def Test = f
inline given f[T <: Foo]: T = ??? match {
case x: T => x.g(10) // error // error
}

@main def Test = f

0 comments on commit 87e45fa

Please sign in to comment.