diff --git a/compiler/test-resources/repl/i3536_bind b/compiler/test-resources/repl/i3536_bind index 96ccdce81356..e1504cc5af3a 100644 --- a/compiler/test-resources/repl/i3536_bind +++ b/compiler/test-resources/repl/i3536_bind @@ -1,4 +1,4 @@ -scala> val res10 @ Some(_) = Option(1) +scala> val res10 @ Some(_) = Option(1): @unchecked val res10: Some[Int] = Some(1) scala> res10 val res11: Some[Int] = Some(1) diff --git a/compiler/test-resources/repl/i3536_patterndef_some b/compiler/test-resources/repl/i3536_patterndef_some index 24c8736b57b9..7492c16288e3 100644 --- a/compiler/test-resources/repl/i3536_patterndef_some +++ b/compiler/test-resources/repl/i3536_patterndef_some @@ -1,4 +1,4 @@ -scala> val Some((res40, res41)) = Option((1, 0)) +scala> val Some((res40, res41)) = Option((1, 0)): @unchecked val res40: Int = 1 val res41: Int = 0 scala> res40 diff --git a/compiler/test-resources/repl/i3966 b/compiler/test-resources/repl/i3966 index 9002c1607405..204a7685f854 100644 --- a/compiler/test-resources/repl/i3966 +++ b/compiler/test-resources/repl/i3966 @@ -1,2 +1,2 @@ -scala> val List(x: _*) = List(1, 2) +scala> val List(x: _*) = List(1, 2): @unchecked val x: Seq[Int] = List(1, 2) diff --git a/compiler/test-resources/repl/patdef b/compiler/test-resources/repl/patdef index 12ba13bcd6d5..7bd06483934a 100644 --- a/compiler/test-resources/repl/patdef +++ b/compiler/test-resources/repl/patdef @@ -1,7 +1,7 @@ scala> val Const, x = 0 val Const: Int = 0 val x: Int = 0 -scala> val (Const, List(`x`, _, a), b) = (0, List(0, 1337, 1), 2) +scala> val (Const, List(`x`, _, a), b) = (0, List(0, 1337, 1), 2): @unchecked val a: Int = 1 val b: Int = 2 scala> val a@b = 0 diff --git a/compiler/test/dotty/tools/dotc/TastyBootstrapTests.scala b/compiler/test/dotty/tools/dotc/TastyBootstrapTests.scala index 3164e11e9b2f..c95630144496 100644 --- a/compiler/test/dotty/tools/dotc/TastyBootstrapTests.scala +++ b/compiler/test/dotty/tools/dotc/TastyBootstrapTests.scala @@ -60,7 +60,7 @@ class TastyBootstrapTests { compileList("lib", librarySources, defaultOptions.and("-Ycheck-reentrant", "-language:experimental.erasedDefinitions", // support declaration of scala.compiletime.erasedValue - // "-source", "future", // TODO: re-enable once we allow : @unchecked in pattern definitions. Right now, lots of narrowing pattern definitions fail. + // "-source", "future", // TODO: re-enable once library uses updated syntax for vararg splices, wildcard imports, and import renaming ))(libGroup) val tastyCoreSources = sources(Paths.get("tasty/src")) diff --git a/compiler/test/dotty/tools/dotc/ast/DesugarTests.scala b/compiler/test/dotty/tools/dotc/ast/DesugarTests.scala index dc736596ed9b..43b71f191bd2 100644 --- a/compiler/test/dotty/tools/dotc/ast/DesugarTests.scala +++ b/compiler/test/dotty/tools/dotc/ast/DesugarTests.scala @@ -26,7 +26,7 @@ class DesugarTests extends DottyTest { val ccTree = tree.find(tree => tree.symbol.name == typeName("Foo")).get val List(_, foo) = defPath(ccTree.symbol, tree).map(_.symbol.info) - val x :: y :: rest = foo.decls.toList + val x :: y :: rest = foo.decls.toList: @unchecked // Make sure we extracted the correct values from foo: assert(x.name == termName("x")) diff --git a/compiler/test/dotty/tools/dotc/printing/PrinterTests.scala b/compiler/test/dotty/tools/dotc/printing/PrinterTests.scala index 23054cdf0dfb..64049453b595 100644 --- a/compiler/test/dotty/tools/dotc/printing/PrinterTests.scala +++ b/compiler/test/dotty/tools/dotc/printing/PrinterTests.scala @@ -47,7 +47,7 @@ class PrinterTests extends DottyTest { checkCompile("typer", source) { (tree, context) => given Context = context - val bar @ Trees.DefDef(_, _, _, _) = tree.find(tree => tree.symbol.name == termName("bar2")).get + val bar @ Trees.DefDef(_, _, _, _) = tree.find(tree => tree.symbol.name == termName("bar2")).get: @unchecked assertEquals("Int & (Boolean | String)", bar.tpt.show) } } diff --git a/compiler/test/dotty/tools/dotc/reporting/UserDefinedErrorMessages.scala b/compiler/test/dotty/tools/dotc/reporting/UserDefinedErrorMessages.scala index bd72ac6c6288..4d73b0d88b55 100644 --- a/compiler/test/dotty/tools/dotc/reporting/UserDefinedErrorMessages.scala +++ b/compiler/test/dotty/tools/dotc/reporting/UserDefinedErrorMessages.scala @@ -26,7 +26,7 @@ class UserDefinedErrorMessages extends ErrorMessagesTest { given Context = itcx assertMessageCount(1, messages) - val (m: NoExplanation) :: Nil = messages + val (m: NoExplanation) :: Nil = messages: @unchecked assertEquals(m.msg, "Could not prove Int =!= Int") } @@ -50,7 +50,7 @@ class UserDefinedErrorMessages extends ErrorMessagesTest { given Context = itcx assertMessageCount(1, messages) - val (m: NoExplanation) :: Nil = messages + val (m: NoExplanation) :: Nil = messages: @unchecked assertEquals(m.msg, "Could not prove Int =!= Int") } @@ -75,7 +75,7 @@ class UserDefinedErrorMessages extends ErrorMessagesTest { given Context = itcx assertMessageCount(1, messages) - val (m: NoExplanation) :: Nil = messages + val (m: NoExplanation) :: Nil = messages: @unchecked assertEquals(m.msg, "Could not prove Int =!= Int") } @@ -97,7 +97,7 @@ class UserDefinedErrorMessages extends ErrorMessagesTest { given Context = itcx assertMessageCount(1, messages) - val (m: NoExplanation) :: Nil = messages + val (m: NoExplanation) :: Nil = messages: @unchecked assertEquals(m.msg, "msg A=Any") } @@ -119,7 +119,7 @@ class UserDefinedErrorMessages extends ErrorMessagesTest { given Context = itcx assertMessageCount(1, messages) - val (m: NoExplanation) :: Nil = messages + val (m: NoExplanation) :: Nil = messages: @unchecked assertEquals(m.msg, "msg A=Any") } diff --git a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala index 963f269af8a6..866647476888 100644 --- a/compiler/test/dotty/tools/repl/ReplCompilerTests.scala +++ b/compiler/test/dotty/tools/repl/ReplCompilerTests.scala @@ -213,18 +213,18 @@ class ReplCompilerTests extends ReplTest: } @Test def `i10214 must show classic MatchError` = initially { - run("val 1 = 2") + run("val 1 = 2: @unchecked") assertEquals("scala.MatchError: 2 (of class java.lang.Integer)", storedOutput().linesIterator.next()) } @Test def `i10214 must show useful regex MatchError` = initially { run("""val r = raw"\d+".r""") } andThen { - run("""val r() = "abc"""") + run("""val r() = "abc": @unchecked""") assertEquals("scala.MatchError: abc (of class java.lang.String)", storedOutput().linesIterator.drop(1).next()) } @Test def `i10214 must show MatchError on literal type` = initially { - run("val (x: 1) = 2") + run("val (x: 1) = 2: @unchecked") assertEquals("scala.MatchError: 2 (of class java.lang.Integer)", storedOutput().linesIterator.next()) } @Test def `i12920 must truncate stack trace to user code` = initially { @@ -328,7 +328,7 @@ class ReplCompilerTests extends ReplTest: } @Test def i14473 = initially { - run("""val (x,y) = if true then "hi" else (42,17)""") + run("""val (x,y) = (if true then "hi" else (42,17)): @unchecked""") val all = lines() assertEquals(2, all.length) assertEquals("scala.MatchError: hi (of class java.lang.String)", all.head) diff --git a/scaladoc/test/dotty/tools/scaladoc/tasty/comments/MemberLookupTests.scala b/scaladoc/test/dotty/tools/scaladoc/tasty/comments/MemberLookupTests.scala index 0b9b88fa5bb8..c246401c75fc 100644 --- a/scaladoc/test/dotty/tools/scaladoc/tasty/comments/MemberLookupTests.scala +++ b/scaladoc/test/dotty/tools/scaladoc/tasty/comments/MemberLookupTests.scala @@ -60,7 +60,7 @@ class LookupTestCases[Q <: Quotes](val q: Quotes) { val target = wrappedTarget.symbol val lookupRes = MemberLookup.lookupOpt(parseQuery(query), None) assertTrue(s"Couldn't look up: $query", lookupRes.nonEmpty) - val Some((lookedUp, _, _)) = lookupRes + val Some((lookedUp, _, _)) = lookupRes: @unchecked assertSame(query, target, lookedUp) } @@ -83,7 +83,7 @@ class LookupTestCases[Q <: Quotes](val q: Quotes) { val target = sym.symbol val lookupRes = MemberLookup.lookupOpt(parseQuery(query), None) assertTrue(s"Couldn't look up: $query", lookupRes.nonEmpty) - val Some((_ , _, Some(owner))) = lookupRes + val Some((_ , _, Some(owner))) = lookupRes: @unchecked assertSame(query, target, owner) } } @@ -102,7 +102,7 @@ class LookupTestCases[Q <: Quotes](val q: Quotes) { val lookupRes = MemberLookup.lookupOpt(parseQuery(query), Some(cls("scala.=:=").symbol)) assertTrue(s"Couldn't look up: $query", lookupRes.nonEmpty) println(lookupRes) - val Some((_ , _, owner)) = lookupRes + val Some((_ , _, owner)) = lookupRes: @unchecked assertSame(query, None, owner) } } @@ -161,7 +161,7 @@ class LookupTestCases[Q <: Quotes](val q: Quotes) { ) cases.foreach { case ((Sym(owner), query), Sym(target)) => - val Some((lookedUp, _, _)) = MemberLookup.lookup(parseQuery(query), owner) + val Some((lookedUp, _, _)) = MemberLookup.lookup(parseQuery(query), owner): @unchecked assertSame(s"$owner / $query", target, lookedUp) } } @@ -176,7 +176,7 @@ class LookupTestCases[Q <: Quotes](val q: Quotes) { given q.type = q def parseQuery(query: String): Query = { - val Right(parsed) = QueryParser(query).tryReadQuery() + val Right(parsed) = QueryParser(query).tryReadQuery(): @unchecked parsed } diff --git a/scaladoc/test/dotty/tools/scaladoc/tasty/comments/QueryParserTests.scala b/scaladoc/test/dotty/tools/scaladoc/tasty/comments/QueryParserTests.scala index 676a11348a5f..0d33a9363bac 100644 --- a/scaladoc/test/dotty/tools/scaladoc/tasty/comments/QueryParserTests.scala +++ b/scaladoc/test/dotty/tools/scaladoc/tasty/comments/QueryParserTests.scala @@ -64,12 +64,12 @@ class QueryParserTests { private def parse(input: String) = QueryParser(input).tryReadQuery() private def testSuccess(input: String, expected: Query) = { - val Right(got) = parse(input) + val Right(got) = parse(input): @unchecked assertEquals(expected, got) } private def testFailAt(input: String, char: Int) = { - val Left(err) = parse(input) + val Left(err) = parse(input): @unchecked assertEquals(s"expected to fail at $char : $input", char, err.at) } } diff --git a/tests/neg-macros/i6432/Macro_1.scala b/tests/neg-macros/i6432/Macro_1.scala index e2628fd45f7f..992cdc62ceaf 100644 --- a/tests/neg-macros/i6432/Macro_1.scala +++ b/tests/neg-macros/i6432/Macro_1.scala @@ -9,7 +9,7 @@ object Macro { import quotes.reflect.* sc match { case '{ StringContext(${Varargs(parts)}*) } => - for (part @ Expr(s) <- parts) + for (case part @ Expr(s) <- parts) report.error(s, part.asTerm.pos) } '{} diff --git a/tests/neg-macros/i6432b/Macro_1.scala b/tests/neg-macros/i6432b/Macro_1.scala index e2628fd45f7f..992cdc62ceaf 100644 --- a/tests/neg-macros/i6432b/Macro_1.scala +++ b/tests/neg-macros/i6432b/Macro_1.scala @@ -9,7 +9,7 @@ object Macro { import quotes.reflect.* sc match { case '{ StringContext(${Varargs(parts)}*) } => - for (part @ Expr(s) <- parts) + for (case part @ Expr(s) <- parts) report.error(s, part.asTerm.pos) } '{} diff --git a/tests/neg/t5702-neg-bad-and-wild.check b/tests/neg/t5702-neg-bad-and-wild.check index 623bf3002cca..f6d761a6726f 100644 --- a/tests/neg/t5702-neg-bad-and-wild.check +++ b/tests/neg/t5702-neg-bad-and-wild.check @@ -56,3 +56,19 @@ | Recursive value $1$ needs type | | longer explanation available when compiling with `-explain` +-- Warning: tests/neg/t5702-neg-bad-and-wild.scala:22:20 --------------------------------------------------------------- +22 | val K(x @ _*) = k + | ^ + | pattern's type Int* does not match the right hand side expression's type Int + | + | If the narrowing is intentional, this can be communicated by adding `: @unchecked` after the expression, + | which may result in a MatchError at runtime. + | This patch can be rewritten automatically under -rewrite -source 3.2-migration. +-- Warning: tests/neg/t5702-neg-bad-and-wild.scala:25:20 --------------------------------------------------------------- +25 | val (b, _ * ) = (5,6) // ok + | ^^^^^ + | pattern's type Int* does not match the right hand side expression's type Int + | + | If the narrowing is intentional, this can be communicated by adding `: @unchecked` after the expression, + | which may result in a MatchError at runtime. + | This patch can be rewritten automatically under -rewrite -source 3.2-migration. diff --git a/tests/patmat/for.scala b/tests/patmat/for.scala index 4c2ed262fc30..14e5de351212 100644 --- a/tests/patmat/for.scala +++ b/tests/patmat/for.scala @@ -3,5 +3,5 @@ object Test { for ((a, b) <- l) yield a } - def bar(xs: List[(Int, List[Int])]): Unit = for ( (_, x :: y :: xs) <- xs) yield x + def bar(xs: List[(Int, List[Int])]): Unit = for (case (_, x :: y :: xs) <- xs) yield x } \ No newline at end of file diff --git a/tests/pos-special/fatal-warnings/i6621.scala b/tests/pos-special/fatal-warnings/i6621.scala index a006c1254ae0..92362a004530 100644 --- a/tests/pos-special/fatal-warnings/i6621.scala +++ b/tests/pos-special/fatal-warnings/i6621.scala @@ -4,5 +4,5 @@ object Unapply { } object Test { - val Unapply(x, y) = "" + val Unapply(x, y) = "": @unchecked } diff --git a/tests/pos/i14587.hard-union-tuples.scala b/tests/pos/i14587.hard-union-tuples.scala index 2d4ebcf93cc0..e1a086655e5f 100644 --- a/tests/pos/i14587.hard-union-tuples.scala +++ b/tests/pos/i14587.hard-union-tuples.scala @@ -3,8 +3,9 @@ class Test: type Foo = Option[String] | Option[Int] def test(foo: Foo) = - val (_, foo2: Foo) = // was: the type test for Test.this.Foo cannot be checked at runtime + val (_, foo2: Foo) = ( // was: the type test for Test.this.Foo cannot be checked at runtime foo match case Some(s: String) => ((), s) case _ => ((), 0) + ): @unchecked foo2 diff --git a/tests/semanticdb/expect/Synthetic.expect.scala b/tests/semanticdb/expect/Synthetic.expect.scala index 2672b8106785..a4419aa8bd82 100644 --- a/tests/semanticdb/expect/Synthetic.expect.scala +++ b/tests/semanticdb/expect/Synthetic.expect.scala @@ -9,11 +9,11 @@ class Synthetic/*<-example::Synthetic#*/ { // See https://github.com/scalameta/scalameta/issues/977 val Name/*<-example::Synthetic#Name.*/ = "name:(.*)".r/*->scala::collection::StringOps#r().*/ - val x/*<-example::Synthetic#x.*/ #::/*->scala::package.`#::`.*/ xs/*<-example::Synthetic#xs.*/ = LazyList/*->scala::package.LazyList.*/(1, 2) - val Name/*->example::Synthetic#Name.*/(name/*<-example::Synthetic#name.*/) = "name:foo" + val x/*<-example::Synthetic#x.*/ #::/*->scala::package.`#::`.*/ xs/*<-example::Synthetic#xs.*/ = LazyList/*->scala::package.LazyList.*/(1, 2): @unchecked + val Name/*->example::Synthetic#Name.*/(name/*<-example::Synthetic#name.*/) = "name:foo": @unchecked 1 #:: 2 #:: LazyList/*->scala::package.LazyList.*/.empty/*->scala::collection::immutable::LazyList.empty().*/ - val a1/*<-example::Synthetic#a1.*/ #::/*->scala::package.`#::`.*/ a2/*<-example::Synthetic#a2.*/ #::/*->scala::package.`#::`.*/ as/*<-example::Synthetic#as.*/ = LazyList/*->scala::package.LazyList.*/(1, 2) + val a1/*<-example::Synthetic#a1.*/ #::/*->scala::package.`#::`.*/ a2/*<-example::Synthetic#a2.*/ #::/*->scala::package.`#::`.*/ as/*<-example::Synthetic#as.*/ = LazyList/*->scala::package.LazyList.*/(1, 2): @unchecked val lst/*<-example::Synthetic#lst.*/ = 1 #:: 2 #:: LazyList/*->scala::package.LazyList.*/.empty/*->scala::collection::immutable::LazyList.empty().*/ diff --git a/tests/semanticdb/expect/Synthetic.scala b/tests/semanticdb/expect/Synthetic.scala index 10d13e936468..71fb5fdf70a3 100644 --- a/tests/semanticdb/expect/Synthetic.scala +++ b/tests/semanticdb/expect/Synthetic.scala @@ -9,11 +9,11 @@ class Synthetic { // See https://github.com/scalameta/scalameta/issues/977 val Name = "name:(.*)".r - val x #:: xs = LazyList(1, 2) - val Name(name) = "name:foo" + val x #:: xs = LazyList(1, 2): @unchecked + val Name(name) = "name:foo": @unchecked 1 #:: 2 #:: LazyList.empty - val a1 #:: a2 #:: as = LazyList(1, 2) + val a1 #:: a2 #:: as = LazyList(1, 2): @unchecked val lst = 1 #:: 2 #:: LazyList.empty