@@ -13,7 +13,7 @@ import Symbols.*
13
13
import Trees .*
14
14
import ProtoTypes .*
15
15
import Decorators .*
16
- import config .MigrationVersion
16
+ import config .MigrationVersion as mv
17
17
import config .Feature .{sourceVersion , migrateTo3 }
18
18
import config .SourceVersion .*
19
19
import reporting .*
@@ -30,6 +30,15 @@ trait Migrations:
30
30
31
31
import tpd .*
32
32
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
+
33
42
/** Flag & migrate `?` used as a higher-kinded type parameter
34
43
* Warning in 3.0-migration, error from 3.0
35
44
*/
@@ -40,7 +49,7 @@ trait Migrations:
40
49
else " "
41
50
val namePos = tree.sourcePos.withSpan(tree.nameSpan)
42
51
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 )
44
53
45
54
def typedAsFunction (tree : untpd.PostfixOp , pt : Type )(using Context ): Tree = {
46
55
val untpd .PostfixOp (qual, Ident (nme.WILDCARD )) = tree : @ unchecked
@@ -52,8 +61,8 @@ trait Migrations:
52
61
case _ =>
53
62
val recovered = typed(qual)(using ctx.fresh.setExploreTyperState())
54
63
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
57
66
// Under -rewrite, patch `x _` to `(() => x)`
58
67
msg.actions
59
68
.headOption
@@ -69,16 +78,16 @@ trait Migrations:
69
78
case _ =>
70
79
(" (() => " , " )" )
71
80
}
81
+ val mversion = mv.FunctionUnderscore
72
82
def remedy =
73
83
if ((prefix ++ suffix).isEmpty) " simply leave out the trailing ` _`"
74
84
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 )
76
86
report.errorOrMigrationWarning(
77
87
em """ The syntax `<function> _` is no longer supported;
78
88
|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
82
91
patch(Span (tree.span.start), prefix)
83
92
patch(Span (qual.span.end, tree.span.end), suffix)
84
93
@@ -89,19 +98,20 @@ trait Migrations:
89
98
* Warning in 3.4, error in 3.5, rewrite in 3.5-migration.
90
99
*/
91
100
def contextBoundParams (tree : Tree , tp : Type , pt : FunProto )(using Context ): Unit =
101
+ val mversion = mv.ExplicitContextBoundArgument
92
102
def isContextBoundParams = tp.stripPoly match
93
103
case MethodType (ContextBoundParamName (_) :: _) => true
94
104
case _ => false
95
105
if sourceVersion.isAtLeast(`3.4`)
96
106
&& isContextBoundParams
97
107
&& pt.applyKind != ApplyKind .Using
98
108
then
99
- def rewriteMsg = Message .rewriteNotice(" This code" , `3.5-migration` )
109
+ def rewriteMsg = Message .rewriteNotice(" This code" , mversion.patchFrom )
100
110
report.errorOrMigrationWarning(
101
111
em """ Context bounds will map to context parameters.
102
112
|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
105
115
patch(Span (pt.args.head.span.start), " using " )
106
116
end contextBoundParams
107
117
0 commit comments