@@ -43,7 +43,7 @@ import config.Printers.{gadts, typr}
4343import config .Feature
4444import config .Feature .{sourceVersion , migrateTo3 }
4545import config .SourceVersion .*
46- import rewrites .Rewrites .patch
46+ import rewrites .Rewrites , Rewrites .patch
4747import staging .StagingLevel
4848import reporting .*
4949import Nullables .*
@@ -53,7 +53,6 @@ import config.Config
5353import config .MigrationVersion
5454
5555import scala .annotation .constructorOnly
56- import dotty .tools .dotc .rewrites .Rewrites
5756
5857object Typer {
5958
@@ -127,7 +126,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
127126 with Dynamic
128127 with Checking
129128 with QuotesAndSplices
130- with Deriving {
129+ with Deriving
130+ with Migrations {
131131
132132 import Typer .*
133133 import tpd .{cpy => _ , _ }
@@ -2978,48 +2978,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
29782978 else tree1
29792979 }
29802980
2981- def typedAsFunction (tree : untpd.PostfixOp , pt : Type )(using Context ): Tree = {
2982- val untpd .PostfixOp (qual, Ident (nme.WILDCARD )) = tree : @ unchecked
2983- val pt1 = if (defn.isFunctionNType(pt)) pt else AnyFunctionProto
2984- val nestedCtx = ctx.fresh.setNewTyperState()
2985- val res = typed(qual, pt1)(using nestedCtx)
2986- res match {
2987- case closure(_, _, _) =>
2988- case _ =>
2989- val recovered = typed(qual)(using ctx.fresh.setExploreTyperState())
2990- val msg = OnlyFunctionsCanBeFollowedByUnderscore (recovered.tpe.widen, tree)
2991- report.errorOrMigrationWarning(msg, tree.srcPos, MigrationVersion .Scala2to3 )
2992- if MigrationVersion .Scala2to3 .needsPatch then
2993- // Under -rewrite, patch `x _` to `(() => x)`
2994- msg.actions
2995- .headOption
2996- .foreach(Rewrites .applyAction)
2997- return typed(untpd.Function (Nil , qual), pt)
2998- }
2999- nestedCtx.typerState.commit()
3000-
3001- lazy val (prefix, suffix) = res match {
3002- case Block (mdef @ DefDef (_, vparams :: Nil , _, _) :: Nil , _ : Closure ) =>
3003- val arity = vparams.length
3004- if (arity > 0 ) (" " , " " ) else (" (() => " , " ())" )
3005- case _ =>
3006- (" (() => " , " )" )
3007- }
3008- def remedy =
3009- if ((prefix ++ suffix).isEmpty) " simply leave out the trailing ` _`"
3010- else s " use ` $prefix<function> $suffix` instead "
3011- def rewrite = Message .rewriteNotice(" This construct" , `3.4-migration`)
3012- report.errorOrMigrationWarning(
3013- em """ The syntax `<function> _` is no longer supported;
3014- |you can $remedy$rewrite""" ,
3015- tree.srcPos,
3016- MigrationVersion .FunctionUnderscore )
3017- if MigrationVersion .FunctionUnderscore .needsPatch then
3018- patch(Span (tree.span.start), prefix)
3019- patch(Span (qual.span.end, tree.span.end), suffix)
3020-
3021- res
3022- }
2981+ override def typedAsFunction (tree : untpd.PostfixOp , pt : Type )(using Context ): Tree =
2982+ migrate(super .typedAsFunction(tree, pt))
30232983
30242984 /** Translate infix operation expression `l op r` to
30252985 *
@@ -3137,13 +3097,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
31373097 case tree : untpd.TypeDef =>
31383098 // separate method to keep dispatching method `typedNamed` short which might help the JIT
31393099 def typedTypeOrClassDef : Tree =
3140- if tree.name eq tpnme.? then
3141- val addendum = if sym.owner.is(TypeParam )
3142- then " , use `_` to denote a higher-kinded type parameter"
3143- else " "
3144- val namePos = tree.sourcePos.withSpan(tree.nameSpan)
3145- report.errorOrMigrationWarning(
3146- em " `?` is not a valid type name $addendum" , namePos, MigrationVersion .Scala2to3 )
3100+ migrate(kindProjectorQMark(tree, sym))
31473101 if tree.isClassDef then
31483102 typedClassDef(tree, sym.asClass)(using ctx.localContext(tree, sym))
31493103 else
@@ -3818,24 +3772,12 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
38183772 def adaptToArgs (wtp : Type , pt : FunProto ): Tree = wtp match {
38193773 case wtp : MethodOrPoly =>
38203774 def methodStr = methPart(tree).symbol.showLocated
3821- if (matchingApply(wtp, pt))
3775+ if matchingApply(wtp, pt) then
3776+ migrate(contextBoundParams(tree, wtp, pt))
38223777 if needsTupledDual(wtp, pt) then adapt(tree, pt.tupledDual, locked)
38233778 else tree
38243779 else if wtp.isContextualMethod then
3825- def isContextBoundParams = wtp.stripPoly match
3826- case MethodType (ContextBoundParamName (_) :: _) => true
3827- case _ => false
3828- if sourceVersion == `future-migration` && isContextBoundParams && pt.args.nonEmpty
3829- then // Under future-migration, don't infer implicit arguments yet for parameters
3830- // coming from context bounds. Issue a warning instead and offer a patch.
3831- def rewriteMsg = Message .rewriteNotice(" This code" , `future-migration`)
3832- report.migrationWarning(
3833- em """ Context bounds will map to context parameters.
3834- |A `using` clause is needed to pass explicit arguments to them. $rewriteMsg""" , tree.srcPos)
3835- patch(Span (pt.args.head.span.start), " using " )
3836- tree
3837- else
3838- adaptNoArgs(wtp) // insert arguments implicitly
3780+ adaptNoArgs(wtp) // insert arguments implicitly
38393781 else if (tree.symbol.isPrimaryConstructor && tree.symbol.info.firstParamTypes.isEmpty)
38403782 readapt(tree.appliedToNone) // insert () to primary constructors
38413783 else
@@ -4441,7 +4383,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
44414383 protected def matchingApply (methType : MethodOrPoly , pt : FunProto )(using Context ): Boolean =
44424384 val isUsingApply = pt.applyKind == ApplyKind .Using
44434385 methType.isContextualMethod == isUsingApply
4444- || methType.isImplicitMethod && isUsingApply // for a transition allow `with ` arguments for regular implicit parameters
4386+ || methType.isImplicitMethod && isUsingApply // for a transition allow `using ` arguments for regular implicit parameters
44454387
44464388 /** Check that `tree == x: pt` is typeable. Used when checking a pattern
44474389 * against a selector of type `pt`. This implementation accounts for
0 commit comments