@@ -218,7 +218,7 @@ self =>
218
218
219
219
override def blockExpr (): Tree = skipBraces(EmptyTree )
220
220
221
- override def templateBody (isPre : Boolean ) = skipBraces((noSelfType, EmptyTree .asList))
221
+ override def templateBody () = skipBraces((noSelfType, EmptyTree .asList))
222
222
}
223
223
224
224
class UnitParser (override val unit : global.CompilationUnit , patches : List [BracePatch ]) extends SourceFileParser (unit.source) { uself =>
@@ -617,22 +617,18 @@ self =>
617
617
and
618
618
}
619
619
620
- // warn under -Xsource:3
621
- def migrationWarning (offset : Offset , msg : String , since : String , actions : List [CodeAction ] = Nil ): Unit =
622
- if (currentRun.isScala3)
623
- warning(offset, msg, WarningCategory .Scala3Migration , actions)
624
-
625
- // warn under -Xsource:3, otherwise deprecation
626
- def hardMigrationWarning (offset : Offset , msg : String , since : String , actions : List [CodeAction ] = Nil ): Unit =
620
+ // warn under -Xsource:3; otherwise if since is nonEmpty, issue a deprecation
621
+ def migrationWarning (offset : Offset , msg : String , since : String = " " , actions : List [CodeAction ] = Nil ): Unit =
627
622
if (currentRun.isScala3) warning(offset, msg, WarningCategory .Scala3Migration , actions)
628
- else deprecationWarning(offset, msg, since, actions)
623
+ else if ( ! since.isEmpty) deprecationWarning(offset, msg, since, actions)
629
624
630
625
// deprecation or migration under -Xsource:3, with different messages
631
- def hardMigrationWarning (offset : Offset , depr : => String , migr : => String , since : String , actions : String => List [CodeAction ]): Unit =
632
- if (currentRun.isScala3) warning(offset, migr, WarningCategory .Scala3Migration , actions(migr))
633
- else deprecationWarning(offset, depr, since, actions(depr))
634
- def hardMigrationWarning (offset : Offset , depr : => String , migr : => String , since : String ): Unit =
635
- hardMigrationWarning(offset, depr, migr, since, _ => Nil )
626
+ def migrationWarning (offset : Offset , depr : => String , migr : => String , since : String , actions : String => List [CodeAction ]): Unit = {
627
+ val msg = if (currentRun.isScala3) migr else depr
628
+ migrationWarning(offset, msg, since, actions(msg))
629
+ }
630
+ def migrationWarning (offset : Offset , depr : => String , migr : => String , since : String ): Unit =
631
+ migrationWarning(offset, depr, migr, since, (_ : String ) => Nil )
636
632
637
633
def expectedMsgTemplate (exp : String , fnd : String ) = s " $exp expected but $fnd found. "
638
634
def expectedMsg (token : Token ): String =
@@ -819,7 +815,7 @@ self =>
819
815
def actions =
820
816
if (tree.pos.isRange) runReporting.codeAction(" add parentheses" , tree.pos, s " ( ${unit.source.sourceAt(tree.pos)}) " , msg)
821
817
else Nil
822
- migrationWarning(tree.pos.point, wrn, " 2.13.11" , actions)
818
+ migrationWarning(tree.pos.point, wrn, /* since= "2.13.11",*/ actions = actions)
823
819
List (convertToParam(tree))
824
820
case _ => List (convertToParam(tree))
825
821
}
@@ -1037,8 +1033,7 @@ self =>
1037
1033
val fun = s " ${CodeAction .maybeWrapInParens(qual)}. ${unit.source.sourceAt(operatorPos.withEnd(rhs.pos.start))}" .trim
1038
1034
val fix = s " $fun${CodeAction .wrapInParens(unit.source.sourceAt(rhs.pos))}"
1039
1035
val msg = " type application is not allowed for infix operators"
1040
- migrationWarning(offset, msg, " 2.13.11" ,
1041
- runReporting.codeAction(" use selection" , pos, fix, msg))
1036
+ migrationWarning(offset, msg, /* since="2.13.11",*/ actions = runReporting.codeAction(" use selection" , pos, fix, msg))
1042
1037
}
1043
1038
atPos(pos)(makeBinop(isExpr, lhs, operator, rhs, operatorPos, targs))
1044
1039
}
@@ -2114,7 +2109,7 @@ self =>
2114
2109
def msg (what : String , instead : String ): String = s " `val` keyword in for comprehension is $what: $instead"
2115
2110
if (hasEq) {
2116
2111
val without = " instead, bind the value without `val`"
2117
- hardMigrationWarning (in.offset, msg(" deprecated" , without), msg(" unsupported" , without), " 2.10.0" , actions)
2112
+ migrationWarning (in.offset, msg(" deprecated" , without), msg(" unsupported" , without), since = " 2.10.0" , actions= actions(_) )
2118
2113
} else {
2119
2114
val m = msg(" unsupported" , " just remove `val`" )
2120
2115
syntaxError(in.offset, m, actions(m))
@@ -2669,7 +2664,7 @@ self =>
2669
2664
val pname : TypeName =
2670
2665
if (in.token == USCORE ) {
2671
2666
if (! isAbstractOwner)
2672
- hardMigrationWarning (in.offset, " Top-level wildcard is not allowed" , " 2.13.7" )
2667
+ migrationWarning (in.offset, " Top-level wildcard is not allowed" , since = " 2.13.7" )
2673
2668
in.nextToken()
2674
2669
freshTypeName(" _$$" )
2675
2670
}
@@ -2682,7 +2677,7 @@ self =>
2682
2677
def msg (what : String ) = s """ view bounds are $what; use an implicit parameter instead.
2683
2678
| example: instead of `def f[A <% Int](a: A)` use `def f[A](a: A)(implicit ev: A => Int)` """ .stripMargin
2684
2679
while (in.token == VIEWBOUND ) {
2685
- hardMigrationWarning (in.offset, msg(" deprecated" ), msg(" unsupported" ), " 2.12.0" )
2680
+ migrationWarning (in.offset, msg(" deprecated" ), msg(" unsupported" ), since = " 2.12.0" )
2686
2681
contextBoundBuf += atPos(in.skipToken())(makeFunctionTypeTree(List (Ident (pname)), typ()))
2687
2682
}
2688
2683
while (in.token == COLON ) {
@@ -3021,18 +3016,17 @@ self =>
3021
3016
if (in.token == THIS ) {
3022
3017
def missingEquals () = {
3023
3018
val msg = " procedure syntax is deprecated for constructors: add `=`, as in method definition"
3024
- hardMigrationWarning(in.lastOffset, msg, " 2.13.2" ,
3025
- runReporting.codeAction(" replace procedure syntax" , o2p(in.lastOffset), " =" , msg))
3019
+ migrationWarning(in.lastOffset, msg, since = " 2.13.2" , actions = runReporting.codeAction(" replace procedure syntax" , o2p(in.lastOffset), " =" , msg))
3026
3020
}
3027
3021
atPos(start, in.skipToken()) {
3028
- val vparamss = paramClauses(nme.CONSTRUCTOR , classContextBounds map (_.duplicate), ofCaseClass = false )
3022
+ val vparamss = paramClauses(nme.CONSTRUCTOR , classContextBounds. map(_.duplicate), ofCaseClass = false )
3029
3023
newLineOptWhenFollowedBy(LBRACE )
3030
3024
val rhs =
3031
3025
if (in.token == LBRACE ) {
3032
- missingEquals(); atPos(in.offset) { constrBlock(vparamss ) }
3026
+ missingEquals(); atPos(in.offset) { constrBlock() }
3033
3027
}
3034
3028
else {
3035
- accept(EQUALS ) ; atPos(in.offset) { constrExpr(vparamss ) }
3029
+ accept(EQUALS ) ; atPos(in.offset) { constrExpr() }
3036
3030
}
3037
3031
DefDef (mods, nme.CONSTRUCTOR , List (), vparamss, TypeTree (), rhs)
3038
3032
}
@@ -3065,13 +3059,13 @@ self =>
3065
3059
val rhs =
3066
3060
if (isStatSep || in.token == RBRACE ) {
3067
3061
if (restype.isEmpty) {
3068
- hardMigrationWarning (in.lastOffset, msg(" deprecated" , " : Unit" ), msg(" unsupported" , " : Unit" ), " 2.13.0" , declActions)
3062
+ migrationWarning (in.lastOffset, msg(" deprecated" , " : Unit" ), msg(" unsupported" , " : Unit" ), since = " 2.13.0" , actions = declActions)
3069
3063
restype = scalaUnitConstr
3070
3064
}
3071
3065
newmods |= Flags .DEFERRED
3072
3066
EmptyTree
3073
3067
} else if (restype.isEmpty && in.token == LBRACE ) {
3074
- hardMigrationWarning (in.offset, msg(" deprecated" , " : Unit =" ), msg(" unsupported" , " : Unit =" ), " 2.13.0" , defnActions)
3068
+ migrationWarning (in.offset, msg(" deprecated" , " : Unit =" ), msg(" unsupported" , " : Unit =" ), since = " 2.13.0" , actions = defnActions)
3075
3069
restype = scalaUnitConstr
3076
3070
blockExpr()
3077
3071
} else {
@@ -3093,7 +3087,7 @@ self =>
3093
3087
val o = nameOffset + name.decode.length
3094
3088
runReporting.codeAction(" remove ()" , r2p(o, o, o + 2 ), " " , msg, expected = Some ((" ()" , unit)))
3095
3089
}
3096
- def warnNilary () = hardMigrationWarning (nameOffset, unaryMsg(" deprecated" ), unaryMsg(" unsupported" ), " 2.13.4" , action)
3090
+ def warnNilary () = migrationWarning (nameOffset, unaryMsg(" deprecated" ), unaryMsg(" unsupported" ), since = " 2.13.4" , actions = action)
3097
3091
vparamss match {
3098
3092
case List (List ()) => warnNilary()
3099
3093
case List (List (), x :: xs) if x.mods.isImplicit => warnNilary()
@@ -3111,15 +3105,15 @@ self =>
3111
3105
* | ConstrBlock
3112
3106
* }}}
3113
3107
*/
3114
- def constrExpr (vparamss : List [ List [ ValDef ]] ): Tree =
3115
- if (in.token == LBRACE ) constrBlock(vparamss )
3116
- else Block (selfInvocation(vparamss ) :: Nil , literalUnit)
3108
+ def constrExpr (): Tree =
3109
+ if (in.token == LBRACE ) constrBlock()
3110
+ else Block (selfInvocation() :: Nil , literalUnit)
3117
3111
3118
3112
/** {{{
3119
3113
* SelfInvocation ::= this ArgumentExprs {ArgumentExprs}
3120
3114
* }}}
3121
3115
*/
3122
- def selfInvocation (vparamss : List [ List [ ValDef ]] ): Tree =
3116
+ def selfInvocation (): Tree =
3123
3117
atPos(accept(THIS )) {
3124
3118
newLineOptWhenFollowedBy(LBRACE )
3125
3119
var t = Apply (Ident (nme.CONSTRUCTOR ), argumentExprs())
@@ -3135,9 +3129,9 @@ self =>
3135
3129
* ConstrBlock ::= `{` SelfInvocation {semi BlockStat} `}`
3136
3130
* }}}
3137
3131
*/
3138
- def constrBlock (vparamss : List [ List [ ValDef ]] ): Tree =
3132
+ def constrBlock (): Tree =
3139
3133
atPos(in.skipToken()) {
3140
- val stats = selfInvocation(vparamss ) :: {
3134
+ val stats = selfInvocation() :: {
3141
3135
if (isStatSep) { in.nextToken(); blockStatSeq() }
3142
3136
else Nil
3143
3137
}
@@ -3224,7 +3218,7 @@ self =>
3224
3218
val nameOffset = in.offset
3225
3219
val name = identForType()
3226
3220
if (currentRun.isScala3 && in.token == LBRACKET && isAfterLineEnd)
3227
- hardMigrationWarning (in.offset, " type parameters should not follow newline" , " 2.13.7" )
3221
+ migrationWarning (in.offset, " type parameters should not follow newline" , since = " 2.13.7" )
3228
3222
def orStart (p : Offset ) = if (name == tpnme.ERROR ) start else p
3229
3223
val namePos = NamePos (r2p(orStart(nameOffset), orStart(nameOffset)))
3230
3224
atPos(start, orStart(nameOffset)) {
@@ -3328,12 +3322,12 @@ self =>
3328
3322
if (in.token == LBRACE ) {
3329
3323
val braceOffset = in.offset
3330
3324
// @S: pre template body cannot stub like post body can!
3331
- val (self, body) = templateBody(isPre = true )
3325
+ val (self, body) = templateBody()
3332
3326
if (in.token == WITH && (self eq noSelfType)) {
3333
3327
val advice =
3334
3328
if (currentRun.isScala3) " use trait parameters instead."
3335
3329
else " they will be replaced by trait parameters in 3.0, see the migration guide on avoiding var/val in traits."
3336
- hardMigrationWarning (braceOffset, s " early initializers are deprecated; $advice" , " 2.13.0" )
3330
+ migrationWarning (braceOffset, s " early initializers are deprecated; $advice" , since = " 2.13.0" )
3337
3331
val earlyDefs : List [Tree ] = body.map(ensureEarlyDef).filter(_.nonEmpty)
3338
3332
in.nextToken()
3339
3333
val parents = templateParents()
@@ -3354,7 +3348,7 @@ self =>
3354
3348
copyValDef(vdef)(mods = mods | Flags .PRESUPER )
3355
3349
case tdef @ TypeDef (mods, name, tparams, rhs) =>
3356
3350
def msg (what : String ): String = s " early type members are $what: move them to the regular body; the semantics are the same "
3357
- hardMigrationWarning (tdef.pos.point, msg(" deprecated" ), msg(" unsupported" ), " 2.11.0" )
3351
+ migrationWarning (tdef.pos.point, msg(" deprecated" ), msg(" unsupported" ), since = " 2.11.0" )
3358
3352
treeCopy.TypeDef (tdef, mods | Flags .PRESUPER , name, tparams, rhs)
3359
3353
case docdef @ DocDef (comm, rhs) =>
3360
3354
treeCopy.DocDef (docdef, comm, rhs)
@@ -3410,16 +3404,15 @@ self =>
3410
3404
/** {{{
3411
3405
* TemplateBody ::= [nl] `{` TemplateStatSeq `}`
3412
3406
* }}}
3413
- * @param isPre specifies whether in early initializer (true) or not (false)
3414
3407
*/
3415
- def templateBody (isPre : Boolean ) = inBraces(templateStatSeq(isPre )) match {
3408
+ def templateBody () = inBraces(templateStatSeq()) match {
3416
3409
case (selfTypeVal, Nil ) => (selfTypeVal, EmptyTree .asList)
3417
3410
case result => result
3418
3411
}
3419
3412
def templateBodyOpt (parenMeansSyntaxError : Boolean ): (ValDef , List [Tree ]) = {
3420
3413
newLineOptWhenFollowedBy(LBRACE )
3421
3414
if (in.token == LBRACE ) {
3422
- templateBody(isPre = false )
3415
+ templateBody()
3423
3416
} else {
3424
3417
if (in.token == LPAREN ) {
3425
3418
if (parenMeansSyntaxError) syntaxError(s " traits or objects may not have parameters " , skipIt = true )
@@ -3482,9 +3475,8 @@ self =>
3482
3475
/** {{{
3483
3476
* TemplateStatSeq ::= [id [`:` Type] `=>`] TemplateStats
3484
3477
* }}}
3485
- * @param isPre specifies whether in early initializer (true) or not (false)
3486
3478
*/
3487
- def templateStatSeq (isPre : Boolean ): (ValDef , List [Tree ]) = {
3479
+ def templateStatSeq (): (ValDef , List [Tree ]) = {
3488
3480
var self : ValDef = noSelfType
3489
3481
var firstOpt : Option [Tree ] = None
3490
3482
if (isExprIntro) checkNoEscapingPlaceholders {
0 commit comments