@@ -13,7 +13,7 @@ import Symbols.*
1313import Trees .*
1414import ProtoTypes .*
1515import Decorators .*
16- import config .MigrationVersion
16+ import config .MigrationVersion as mv
1717import config .Feature .{sourceVersion , migrateTo3 }
1818import config .SourceVersion .*
1919import reporting .*
@@ -30,6 +30,15 @@ trait Migrations:
3030
3131 import tpd .*
3232
33+ /** Run `migration`, asserting we are in the proper Typer (not a ReTyper) */
34+ inline def migrate [T ](inline migration : T ): T =
35+ assert(! this .isInstanceOf [ReTyper ])
36+ migration
37+
38+ /** Run `migration`, provided we are in the proper Typer (not a ReTyper) */
39+ inline def migrate (inline migration : Unit ): Unit =
40+ if ! this .isInstanceOf [ReTyper ] then migration
41+
3342 /** Flag & migrate `?` used as a higher-kinded type parameter
3443 * Warning in 3.0-migration, error from 3.0
3544 */
@@ -40,7 +49,7 @@ trait Migrations:
4049 else " "
4150 val namePos = tree.sourcePos.withSpan(tree.nameSpan)
4251 report.errorOrMigrationWarning(
43- em " `?` is not a valid type name $addendum" , namePos, MigrationVersion .Scala2to3 )
52+ em " `?` is not a valid type name $addendum" , namePos, mv .Scala2to3 )
4453
4554 def typedAsFunction (tree : untpd.PostfixOp , pt : Type )(using Context ): Tree = {
4655 val untpd .PostfixOp (qual, Ident (nme.WILDCARD )) = tree : @ unchecked
@@ -52,8 +61,8 @@ trait Migrations:
5261 case _ =>
5362 val recovered = typed(qual)(using ctx.fresh.setExploreTyperState())
5463 val msg = OnlyFunctionsCanBeFollowedByUnderscore (recovered.tpe.widen, tree)
55- report.errorOrMigrationWarning(msg, tree.srcPos, MigrationVersion .Scala2to3 )
56- if MigrationVersion .Scala2to3 .needsPatch then
64+ report.errorOrMigrationWarning(msg, tree.srcPos, mv .Scala2to3 )
65+ if mv .Scala2to3 .needsPatch then
5766 // Under -rewrite, patch `x _` to `(() => x)`
5867 msg.actions
5968 .headOption
@@ -69,16 +78,16 @@ trait Migrations:
6978 case _ =>
7079 (" (() => " , " )" )
7180 }
81+ val mversion = mv.FunctionUnderscore
7282 def remedy =
7383 if ((prefix ++ suffix).isEmpty) " simply leave out the trailing ` _`"
7484 else s " use ` $prefix<function> $suffix` instead "
75- def rewrite = Message .rewriteNotice(" This construct" , `3.4-migration` )
85+ def rewrite = Message .rewriteNotice(" This construct" , mversion.patchFrom )
7686 report.errorOrMigrationWarning(
7787 em """ The syntax `<function> _` is no longer supported;
7888 |you can $remedy$rewrite""" ,
79- tree.srcPos,
80- MigrationVersion .FunctionUnderscore )
81- if MigrationVersion .FunctionUnderscore .needsPatch then
89+ tree.srcPos, mversion)
90+ if mversion.needsPatch then
8291 patch(Span (tree.span.start), prefix)
8392 patch(Span (qual.span.end, tree.span.end), suffix)
8493
@@ -89,19 +98,20 @@ trait Migrations:
8998 * Warning in 3.4, error in 3.5, rewrite in 3.5-migration.
9099 */
91100 def contextBoundParams (tree : Tree , tp : Type , pt : FunProto )(using Context ): Unit =
101+ val mversion = mv.ExplicitContextBoundArgument
92102 def isContextBoundParams = tp.stripPoly match
93103 case MethodType (ContextBoundParamName (_) :: _) => true
94104 case _ => false
95105 if sourceVersion.isAtLeast(`3.4`)
96106 && isContextBoundParams
97107 && pt.applyKind != ApplyKind .Using
98108 then
99- def rewriteMsg = Message .rewriteNotice(" This code" , `3.5-migration` )
109+ def rewriteMsg = Message .rewriteNotice(" This code" , mversion.patchFrom )
100110 report.errorOrMigrationWarning(
101111 em """ Context bounds will map to context parameters.
102112 |A `using` clause is needed to pass explicit arguments to them. $rewriteMsg""" ,
103- tree.srcPos, MigrationVersion (`3.4`, `3.5`) )
104- if sourceVersion.isAtLeast(`3.5-migration`) then
113+ tree.srcPos, mversion )
114+ if mversion.needsPatch then
105115 patch(Span (pt.args.head.span.start), " using " )
106116 end contextBoundParams
107117
0 commit comments