@@ -1054,8 +1054,9 @@ trait Checking {
10541054 }
10551055
10561056 /** Check that pattern `pat` is irrefutable for scrutinee type `sel.tpe`.
1057- * This means `sel` is either marked @unchecked or `sel.tpe` conforms to the
1058- * pattern's type. If pattern is an UnApply, also check that the extractor is
1057+ * This means `sel` is either marked `: @RuntimeChecked`, `: @unchecked` (old style),
1058+ * or `sel.tpe` conforms to the pattern's type. If pattern is an Unapply,
1059+ * also check that the extractor is
10591060 * irrefutable, and do the check recursively.
10601061 */
10611062 def checkIrrefutable (sel : Tree , pat : Tree , isPatDef : Boolean )(using Context ): Boolean = {
@@ -1068,7 +1069,7 @@ trait Checking {
10681069 import Reason .*
10691070 val message = reason match
10701071 case NonConforming =>
1071- var reportedPt = pt.dropAnnot(defn.UncheckedAnnot )
1072+ var reportedPt = pt.dropAnnot(defn.UncheckedAnnot ).dropAnnot(defn. RuntimeCheckedAnnot )
10721073 if ! pat.tpe.isSingleton then reportedPt = reportedPt.widen
10731074 val problem = if pat.tpe <:< reportedPt then " is more specialized than" else " does not match"
10741075 em " pattern's type ${pat.tpe} $problem the right hand side expression's type $reportedPt"
@@ -1084,7 +1085,10 @@ trait Checking {
10841085 else em " pattern binding uses refutable extractor ` $extractor` "
10851086
10861087 val fix =
1087- if isPatDef then " adding `: @unchecked` after the expression"
1088+ if isPatDef then
1089+ val patchText =
1090+ if sourceVersion.isAtLeast(`3.8`) then " .runtimeChecked" else " : @unchecked"
1091+ s " adding ` $patchText` after the expression "
10881092 else " adding the `case` keyword before the full pattern"
10891093 val addendum =
10901094 if isPatDef then " may result in a MatchError at runtime"
@@ -1097,7 +1101,9 @@ trait Checking {
10971101 case NonConforming => sel.srcPos
10981102 case RefutableExtractor => pat.source.atSpan(pat.span `union` sel.span)
10991103 else pat.srcPos
1100- def rewriteMsg = Message .rewriteNotice(" This patch" , `3.2-migration`)
1104+ def rewriteMsg = Message .rewriteNotice(" This patch" ,
1105+ if isPatDef && sourceVersion.isAtLeast(`3.8`) then `3.8-migration` else `3.2-migration`
1106+ )
11011107 report.errorOrMigrationWarning(
11021108 message.append(
11031109 i """ |
@@ -1106,7 +1112,7 @@ trait Checking {
11061112 |which $addendum. $rewriteMsg""" ),
11071113 pos,
11081114 // we tighten for-comprehension without `case` to error in 3.4,
1109- // but we keep pat-defs as warnings for now ("@unchecked "),
1115+ // but we keep pat-defs as warnings for now (".runtimeChecked "),
11101116 // until we propose an alternative way to assert exhaustivity to the typechecker.
11111117 if isPatDef then MigrationVersion .ForComprehensionUncheckedPathDefs
11121118 else MigrationVersion .ForComprehensionPatternWithoutCase
0 commit comments