@@ -43,18 +43,16 @@ import config.Printers.{gadts, typr}
43
43
import config .Feature
44
44
import config .Feature .{sourceVersion , migrateTo3 }
45
45
import config .SourceVersion .*
46
- import rewrites .Rewrites .patch
46
+ import rewrites .Rewrites , Rewrites .patch
47
47
import staging .StagingLevel
48
48
import reporting .*
49
49
import Nullables .*
50
50
import NullOpsDecorator .*
51
51
import cc .CheckCaptures
52
52
import config .Config
53
53
import config .MigrationVersion
54
- import Migrations .*
55
54
56
55
import scala .annotation .constructorOnly
57
- import dotty .tools .dotc .rewrites .Rewrites
58
56
59
57
object Typer {
60
58
@@ -128,7 +126,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
128
126
with Dynamic
129
127
with Checking
130
128
with QuotesAndSplices
131
- with Deriving {
129
+ with Deriving
130
+ with Migrations {
132
131
133
132
import Typer .*
134
133
import tpd .{cpy => _ , _ }
@@ -159,6 +158,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
159
158
// Overridden in derived typers
160
159
def newLikeThis (nestingLevel : Int ): Typer = new Typer (nestingLevel)
161
160
161
+ // Overridden to do nothing in derived typers
162
+ protected def migrate [T ](migration : => T , disabled : => T = ()): T = migration
163
+
162
164
/** Find the type of an identifier with given `name` in given context `ctx`.
163
165
* @param name the name of the identifier
164
166
* @param pt the expected type
@@ -2979,48 +2981,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2979
2981
else tree1
2980
2982
}
2981
2983
2982
- def typedAsFunction (tree : untpd.PostfixOp , pt : Type )(using Context ): Tree = {
2983
- val untpd .PostfixOp (qual, Ident (nme.WILDCARD )) = tree : @ unchecked
2984
- val pt1 = if (defn.isFunctionNType(pt)) pt else AnyFunctionProto
2985
- val nestedCtx = ctx.fresh.setNewTyperState()
2986
- val res = typed(qual, pt1)(using nestedCtx)
2987
- res match {
2988
- case closure(_, _, _) =>
2989
- case _ =>
2990
- val recovered = typed(qual)(using ctx.fresh.setExploreTyperState())
2991
- val msg = OnlyFunctionsCanBeFollowedByUnderscore (recovered.tpe.widen, tree)
2992
- report.errorOrMigrationWarning(msg, tree.srcPos, MigrationVersion .Scala2to3 )
2993
- if MigrationVersion .Scala2to3 .needsPatch then
2994
- // Under -rewrite, patch `x _` to `(() => x)`
2995
- msg.actions
2996
- .headOption
2997
- .foreach(Rewrites .applyAction)
2998
- return typed(untpd.Function (Nil , qual), pt)
2999
- }
3000
- nestedCtx.typerState.commit()
3001
-
3002
- lazy val (prefix, suffix) = res match {
3003
- case Block (mdef @ DefDef (_, vparams :: Nil , _, _) :: Nil , _ : Closure ) =>
3004
- val arity = vparams.length
3005
- if (arity > 0 ) (" " , " " ) else (" (() => " , " ())" )
3006
- case _ =>
3007
- (" (() => " , " )" )
3008
- }
3009
- def remedy =
3010
- if ((prefix ++ suffix).isEmpty) " simply leave out the trailing ` _`"
3011
- else s " use ` $prefix<function> $suffix` instead "
3012
- def rewrite = Message .rewriteNotice(" This construct" , `3.4-migration`)
3013
- report.errorOrMigrationWarning(
3014
- em """ The syntax `<function> _` is no longer supported;
3015
- |you can $remedy$rewrite""" ,
3016
- tree.srcPos,
3017
- MigrationVersion .FunctionUnderscore )
3018
- if MigrationVersion .FunctionUnderscore .needsPatch then
3019
- patch(Span (tree.span.start), prefix)
3020
- patch(Span (qual.span.end, tree.span.end), suffix)
3021
-
3022
- res
3023
- }
2984
+ override def typedAsFunction (tree : untpd.PostfixOp , pt : Type )(using Context ): Tree =
2985
+ migrate(super .typedAsFunction(tree, pt), throw new AssertionError (" can't retype a PostfixOp" ))
3024
2986
3025
2987
/** Translate infix operation expression `l op r` to
3026
2988
*
@@ -3138,7 +3100,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3138
3100
case tree : untpd.TypeDef =>
3139
3101
// separate method to keep dispatching method `typedNamed` short which might help the JIT
3140
3102
def typedTypeOrClassDef : Tree =
3141
- migrateKindProjectorQMark( tree, sym)
3103
+ migrate(kindProjectorQMark( tree, sym) )
3142
3104
if tree.isClassDef then
3143
3105
typedClassDef(tree, sym.asClass)(using ctx.localContext(tree, sym))
3144
3106
else
@@ -3814,7 +3776,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3814
3776
case wtp : MethodOrPoly =>
3815
3777
def methodStr = methPart(tree).symbol.showLocated
3816
3778
if matchingApply(wtp, pt) then
3817
- migrateContextBoundParams( tree, wtp, pt)
3779
+ migrate(contextBoundParams( tree, wtp, pt) )
3818
3780
if needsTupledDual(wtp, pt) then adapt(tree, pt.tupledDual, locked)
3819
3781
else tree
3820
3782
else if wtp.isContextualMethod then
0 commit comments