Skip to content

Commit d740b53

Browse files
committed
Set source version to future under magic
1 parent a2a2384 commit d740b53

34 files changed

Lines changed: 203 additions & 173 deletions

compiler/src/dotty/tools/dotc/config/Feature.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ object Feature:
348348
true
349349
case `magic` =>
350350
ctx.compilationUnit.magic = true
351+
ctx.compilationUnit.sourceVersion = Some(SourceVersion.future)
351352
true
352353
case `inlineTraits` =>
353354
ctx.compilationUnit.knowsInlineTraits = true

tests/neg/i1793-maybe.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ object Test {
44
import scala.ref.WeakReference
55
def unapply[T <: AnyVal](wr: WeakReference[T]): T? = {
66
val x = wr.underlying.get
7-
if (x != null) x else null // error
7+
if x != null then x else null // error
88
}
99
}

tests/neg/i2378-maybe.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ trait Toolbox {
1414

1515
trait ApplyImpl {
1616
def unapply(tree: Tree): (Tree, Seq[Tree])?
17-
def unapply(tree: tpd.Tree)(implicit c: Cap): (tpd.Tree, Seq[tpd.Tree])?
17+
def unapply(tree: tpd.Tree)(using c: Cap): (tpd.Tree, Seq[tpd.Tree])?
1818
}
1919
}
2020

2121
class Test(val tb: Toolbox) {
2222
import tb.*
23-
implicit val cap: Cap = null.asInstanceOf[Cap]
23+
given cap: Cap = null.asInstanceOf[Cap]
2424

2525
def foo(tree: Tree): Int = (tree: Any) match {
2626
case tb.Apply(fun, args) => 3 // error: ambiguous overload of unapply

tests/neg/patmat2-maybe.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import java.lang.IllegalArgumentException
66

77
object IAE {
88
def unapply(e: Exception): String? =
9-
if (e.isInstanceOf[IllegalArgumentException]) e.getMessage
9+
if e.isInstanceOf[IllegalArgumentException] then e.getMessage
1010
else null
1111
}
1212

tests/neg/refutable-pattern-binding-messages-maybe.check

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
-- Error: tests/neg/refutable-pattern-binding-messages-maybe.scala:6:14 ------------------------------------------------
2+
6 | val Positive(p) = 5 // error: refutable extractor
3+
| ^^^^^^^^^^^^^^^
4+
| pattern binding uses refutable extractor `Test.Positive`
5+
|
6+
| If this usage is intentional, this can be communicated by adding `.runtimeChecked` after the expression,
7+
| which may result in a MatchError at runtime.
8+
| This patch can be rewritten automatically under -rewrite -source 3.8-migration.
19
-- Error: tests/neg/refutable-pattern-binding-messages-maybe.scala:7:14 ------------------------------------------------
210
7 | for Positive(i) <- List(1, 2, 3) do () // error: refutable extractor
311
| ^^^^^^^^^^^
@@ -6,6 +14,14 @@
614
| If this usage is intentional, this can be communicated by adding the `case` keyword before the full pattern,
715
| which will result in a filtering for expression (using `withFilter`).
816
| This patch can be rewritten automatically under -rewrite -source 3.2-migration.
17+
-- Error: tests/neg/refutable-pattern-binding-messages-maybe.scala:11:20 -----------------------------------------------
18+
11 | val i :: is = List(1, 2, 3) // error: pattern type more specialized
19+
| ^^^^^^^^^^^^^
20+
| pattern's type ::[Int] is more specialized than the right hand side expression's type List[Int]
21+
|
22+
| If the narrowing is intentional, this can be communicated by adding `.runtimeChecked` after the expression,
23+
| which may result in a MatchError at runtime.
24+
| This patch can be rewritten automatically under -rewrite -source 3.8-migration.
925
-- Error: tests/neg/refutable-pattern-binding-messages-maybe.scala:12:11 -----------------------------------------------
1026
12 | for ((x: String) <- xs) do () // error: pattern type more specialized
1127
| ^^^^^^
@@ -22,24 +38,8 @@
2238
| If the narrowing is intentional, this can be communicated by adding the `case` keyword before the full pattern,
2339
| which will result in a filtering for expression (using `withFilter`).
2440
| This patch can be rewritten automatically under -rewrite -source 3.2-migration.
25-
-- Warning: tests/neg/refutable-pattern-binding-messages-maybe.scala:6:14 ----------------------------------------------
26-
6 | val Positive(p) = 5 // warn: refutable extractor
27-
| ^^^^^^^^^^^^^^^
28-
| pattern binding uses refutable extractor `Test.Positive`
29-
|
30-
| If this usage is intentional, this can be communicated by adding `.runtimeChecked` after the expression,
31-
| which may result in a MatchError at runtime.
32-
| This patch can be rewritten automatically under -rewrite -source 3.8-migration.
33-
-- Warning: tests/neg/refutable-pattern-binding-messages-maybe.scala:11:20 ---------------------------------------------
34-
11 | val i :: is = List(1, 2, 3) // warn: pattern type more specialized
35-
| ^^^^^^^^^^^^^
36-
| pattern's type ::[Int] is more specialized than the right hand side expression's type List[Int]
37-
|
38-
| If the narrowing is intentional, this can be communicated by adding `.runtimeChecked` after the expression,
39-
| which may result in a MatchError at runtime.
40-
| This patch can be rewritten automatically under -rewrite -source 3.8-migration.
41-
-- Warning: tests/neg/refutable-pattern-binding-messages-maybe.scala:17:10 ---------------------------------------------
42-
17 | val 1 = 2 // warn: pattern type does not match
41+
-- Error: tests/neg/refutable-pattern-binding-messages-maybe.scala:17:10 -----------------------------------------------
42+
17 | val 1 = 2 // error: pattern type does not match
4343
| ^
4444
| pattern's type (1 : Int) does not match the right hand side expression's type (2 : Int)
4545
|
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
//> using options -source 3.8 -Yexplicit-nulls
1+
//> using options -Yexplicit-nulls
22
import language.experimental.magic
33
object Test {
44
// refutable extractor
55
object Positive { def unapply(i: Int): Int? = if i > 0 then i else null }
6-
val Positive(p) = 5 // warn: refutable extractor
6+
val Positive(p) = 5 // error: refutable extractor
77
for Positive(i) <- List(1, 2, 3) do () // error: refutable extractor
88

99
// more specialized
1010
val xs: List[AnyRef] = ???
11-
val i :: is = List(1, 2, 3) // warn: pattern type more specialized
11+
val i :: is = List(1, 2, 3) // error: pattern type more specialized
1212
for ((x: String) <- xs) do () // error: pattern type more specialized
1313

1414
// does not match
1515
val ys: List[Option[?]] = ???
1616
for none @ None <- ys do () // error: pattern type does not match
17-
val 1 = 2 // warn: pattern type does not match
17+
val 1 = 2 // error: pattern type does not match
1818
}

tests/neg/unchecked-patterns-maybe.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@ object Test {
66
val (y1: Some[Int]) = Some(1): Option[Int] @unchecked // OK
77
val y2: Some[Int] @unchecked = Some(1): Option[Int] // error
88

9-
val x :: xs = List(1, 2, 3) // warn
10-
val (1, c) = (1, 2) // warn
11-
val 1 *: cs = 1 *: Tuple() // warn
9+
val x :: xs = List(1, 2, 3) // error
10+
val (1, c) = (1, 2) // error
11+
val 1 *: cs = 1 *: Tuple() // error
1212

13-
val (_: Int | _: AnyRef) = ??? : AnyRef // warn
13+
val (_: Int | _: AnyRef) = ??? : AnyRef // error
1414

15-
val 1 = 2 // warn
15+
val 1 = 2 // error
1616

1717
object Positive { def unapply(i: Int): Int? = if i > 0 then i else null }
1818
object Always1 { def unapply(i: Int): Some[Int] = Some(i) }
1919
object Pair { def unapply(t: (Int, Int)): t.type = t }
2020
object Triple { def unapply(t: (Int, Int, Int)): (Int, Int, Int) = t }
2121

22-
val Positive(p) = 5 // warn
23-
val Some(s1) = Option(1) // warn
22+
val Positive(p) = 5 // error
23+
val Some(s1) = Option(1) // error
2424
val Some(s2) = Some(1) // OK
2525
val Always1(p1) = 5 // OK
2626
val Pair(t1, t2) = (5, 5) // OK
2727
val Triple(u1, u2, u3) = (5, 5, 5) // OK
2828
}
29-
// nopos-error: No warnings can be incurred under -Werror (or -Xfatal-warnings)

tests/new/test.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import language.experimental.magic
2+
import language.future
23
import scala.magic.*
34
import scala.util.Either
45

@@ -11,4 +12,5 @@ object Extract:
1112
def unapply[T](x: T): T ? String = Ok(x)
1213

1314
@main def Test = 22 match
14-
case Extract(s) => println(s)
15+
case Extract(s) =>
16+
if (true) println(s)

tests/patmat/optionless-maybe.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
-- [E029] Pattern Match Exhaustivity Warning: tests/patmat/optionless-maybe.scala:30:44
2-
30 | def qux(t: Tree)(implicit c: Cap): Unit = t match {
3-
| ^
1+
-- [E029] Pattern Match Exhaustivity Warning: tests/patmat/optionless-maybe.scala:30:41
2+
30 | def qux(t: Tree)(using c: Cap): Unit = t match {
3+
| ^
44
| match may not be exhaustive.
55
|
66
| It would fail on pattern case: Ident(_)

tests/patmat/optionless-maybe.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ object Ident1 {
99

1010
trait Cap
1111
object Ident2 {
12-
def unapply(tree: Tree)(implicit any: Cap): Ident = ???
12+
def unapply(tree: Tree)(using any: Cap): Ident = ???
1313
}
1414

1515
object Ident3 {
16-
def unapply(tree: Tree)(implicit any: Cap): Ident? = ???
16+
def unapply(tree: Tree)(using any: Cap): Ident? = ???
1717
}
1818

1919

@@ -23,11 +23,11 @@ class Test {
2323
case Ident1(t) =>
2424
}
2525

26-
def bar(t: Tree)(implicit c: Cap): Unit = t match {
26+
def bar(t: Tree)(using c: Cap): Unit = t match {
2727
case Ident2(t) =>
2828
}
2929

30-
def qux(t: Tree)(implicit c: Cap): Unit = t match {
30+
def qux(t: Tree)(using c: Cap): Unit = t match {
3131
case Ident3(t) =>
3232
}
3333

0 commit comments

Comments
 (0)