@@ -43,7 +43,7 @@ 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 .*
@@ -53,7 +53,6 @@ import config.Config
53
53
import config .MigrationVersion
54
54
55
55
import scala .annotation .constructorOnly
56
- import dotty .tools .dotc .rewrites .Rewrites
57
56
58
57
object Typer {
59
58
@@ -127,7 +126,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
127
126
with Dynamic
128
127
with Checking
129
128
with QuotesAndSplices
130
- with Deriving {
129
+ with Deriving
130
+ with Migrations {
131
131
132
132
import Typer .*
133
133
import tpd .{cpy => _ , _ }
@@ -2978,48 +2978,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
2978
2978
else tree1
2979
2979
}
2980
2980
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))
3023
2983
3024
2984
/** Translate infix operation expression `l op r` to
3025
2985
*
@@ -3137,13 +3097,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3137
3097
case tree : untpd.TypeDef =>
3138
3098
// separate method to keep dispatching method `typedNamed` short which might help the JIT
3139
3099
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))
3147
3101
if tree.isClassDef then
3148
3102
typedClassDef(tree, sym.asClass)(using ctx.localContext(tree, sym))
3149
3103
else
@@ -3818,24 +3772,12 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
3818
3772
def adaptToArgs (wtp : Type , pt : FunProto ): Tree = wtp match {
3819
3773
case wtp : MethodOrPoly =>
3820
3774
def methodStr = methPart(tree).symbol.showLocated
3821
- if (matchingApply(wtp, pt))
3775
+ if matchingApply(wtp, pt) then
3776
+ migrate(contextBoundParams(tree, wtp, pt))
3822
3777
if needsTupledDual(wtp, pt) then adapt(tree, pt.tupledDual, locked)
3823
3778
else tree
3824
3779
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
3839
3781
else if (tree.symbol.isPrimaryConstructor && tree.symbol.info.firstParamTypes.isEmpty)
3840
3782
readapt(tree.appliedToNone) // insert () to primary constructors
3841
3783
else
@@ -4441,7 +4383,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4441
4383
protected def matchingApply (methType : MethodOrPoly , pt : FunProto )(using Context ): Boolean =
4442
4384
val isUsingApply = pt.applyKind == ApplyKind .Using
4443
4385
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
4445
4387
4446
4388
/** Check that `tree == x: pt` is typeable. Used when checking a pattern
4447
4389
* against a selector of type `pt`. This implementation accounts for
0 commit comments