Skip to content

Commit 71f5da3

Browse files
committed
add 3.2 language mode, treat it like 3.0, 3.1
it is not available to be set by the user. Future PR can make it visible to the user, or behave differently to 3.0 language mode.
1 parent 9cbee41 commit 71f5da3

File tree

8 files changed

+36
-28
lines changed

8 files changed

+36
-28
lines changed

compiler/src/dotty/tools/dotc/config/Feature.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ object Feature:
8989
* and return `true`, otherwise return `false`.
9090
*/
9191
def warnOnMigration(msg: Message, pos: SrcPos,
92-
version: SourceVersion = defaultSourceVersion)(using Context): Boolean =
92+
version: SourceVersion)(using Context): Boolean =
9393
if sourceVersion.isMigrating && sourceVersion.stable == version
94-
|| (version == `3.0` || version == `3.1`) && migrateTo3
94+
|| (version == `3.0` || version == `3.1` || version == `3.2`) && migrateTo3
9595
then
9696
report.migrationWarning(msg, pos)
9797
true

compiler/src/dotty/tools/dotc/config/SourceVersion.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import core.Decorators.*
66
import util.Property
77

88
enum SourceVersion:
9-
case `3.0-migration`, `3.0`, `3.1`, `future-migration`, `future`
9+
case `3.0-migration`, `3.0`, `3.1`, `3.2`, `future-migration`, `future`
1010

1111
val isMigrating: Boolean = toString.endsWith("-migration")
1212

@@ -16,7 +16,6 @@ enum SourceVersion:
1616
def isAtLeast(v: SourceVersion) = stable.ordinal >= v.ordinal
1717

1818
object SourceVersion extends Property.Key[SourceVersion]:
19-
def defaultSourceVersion = `3.0`
2019

2120
val allSourceVersionNames = values.toList.map(_.toString.toTermName)
2221
end SourceVersion

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ object Parsers {
439439
case t: Typed =>
440440
report.errorOrMigrationWarning(
441441
em"parentheses are required around the parameter of a lambda${rewriteNotice()}",
442-
in.sourcePos())
442+
in.sourcePos(), from = `3.0`)
443443
if migrateTo3 then
444444
patch(source, t.span.startPos, "(")
445445
patch(source, t.span.endPos, ")")
@@ -1180,7 +1180,7 @@ object Parsers {
11801180
|or enclose in braces '{$name} if you want a quoted expression.
11811181
|For now, you can also `import language.deprecated.symbolLiterals` to accept
11821182
|the idiom, but this possibility might no longer be available in the future.""",
1183-
in.sourcePos())
1183+
in.sourcePos(), from = `3.0`)
11841184
if migrateTo3 then
11851185
patch(source, Span(in.offset, in.offset + 1), "Symbol(\"")
11861186
patch(source, Span(in.charOffset - 1), "\")")
@@ -1272,7 +1272,7 @@ object Parsers {
12721272
i"""This opening brace will start a new statement in Scala 3.
12731273
|It needs to be indented to the right to keep being treated as
12741274
|an argument to the previous expression.${rewriteNotice()}""",
1275-
in.sourcePos())
1275+
in.sourcePos(), from = `3.0`)
12761276
patch(source, Span(in.offset), " ")
12771277

12781278
def possibleTemplateStart(isNew: Boolean = false): Unit =
@@ -1826,7 +1826,7 @@ object Parsers {
18261826
else if in.token == VIEWBOUND then
18271827
report.errorOrMigrationWarning(
18281828
"view bounds `<%' are no longer supported, use a context bound `:' instead",
1829-
in.sourcePos())
1829+
in.sourcePos(), from = `3.0`)
18301830
atSpan(in.skipToken()) {
18311831
Function(Ident(pname) :: Nil, toplevelTyp())
18321832
} :: contextBounds(pname)
@@ -1976,7 +1976,7 @@ object Parsers {
19761976
report.errorOrMigrationWarning(
19771977
i"""`do <body> while <cond>` is no longer supported,
19781978
|use `while <body> ; <cond> do ()` instead.${rewriteNotice()}""",
1979-
in.sourcePos())
1979+
in.sourcePos(), from = `3.0`)
19801980
val start = in.skipToken()
19811981
atSpan(start) {
19821982
val body = expr()
@@ -2096,7 +2096,7 @@ object Parsers {
20962096
report.errorOrMigrationWarning(
20972097
em"""`_*` can be used only for last argument of method application.
20982098
|It is no longer allowed in operands of infix operations.""",
2099-
in.sourcePos(uscoreStart))
2099+
in.sourcePos(uscoreStart), from = `3.0`)
21002100
else
21012101
syntaxError(SeqWildcardPatternPos(), uscoreStart)
21022102
Typed(t, atSpan(uscoreStart) { Ident(tpnme.WILDCARD_STAR) })
@@ -3347,7 +3347,7 @@ object Parsers {
33473347
if migrateTo3 then
33483348
report.errorOrMigrationWarning(
33493349
s"Procedure syntax no longer supported; `$toInsert` should be inserted here",
3350-
in.sourcePos())
3350+
in.sourcePos(), from = `3.0`)
33513351
patch(source, Span(in.lastOffset), toInsert)
33523352
true
33533353
else
@@ -3756,7 +3756,7 @@ object Parsers {
37563756
if (in.token == LBRACE || in.token == COLONEOL) {
37573757
report.errorOrMigrationWarning(
37583758
"`extends` must be followed by at least one parent",
3759-
in.sourcePos())
3759+
in.sourcePos(), from = `3.0`)
37603760
Nil
37613761
}
37623762
else constrApps()

compiler/src/dotty/tools/dotc/parsing/Scanners.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import scala.collection.immutable.SortedMap
1818
import rewrites.Rewrites.patch
1919
import config.Feature
2020
import config.Feature.migrateTo3
21+
import config.SourceVersion.`3.0`
2122

2223
object Scanners {
2324

@@ -255,7 +256,10 @@ object Scanners {
255256
def handleMigration(keyword: Token): Token =
256257
if scala3keywords.contains(keyword) && migrateTo3 then
257258
val what = tokenString(keyword)
258-
report.errorOrMigrationWarning(i"$what is now a keyword, write `$what` instead of $what to keep it as an identifier", sourcePos())
259+
report.errorOrMigrationWarning(
260+
i"$what is now a keyword, write `$what` instead of $what to keep it as an identifier",
261+
sourcePos(),
262+
from = `3.0`)
259263
patch(source, Span(offset), "`")
260264
patch(source, Span(offset + identifier.length), "`")
261265
IDENTIFIER
@@ -427,7 +431,7 @@ object Scanners {
427431
em"""$what starts with an operator;
428432
|it is now treated as a continuation of the $previous,
429433
|not as a separate statement.""",
430-
sourcePos())
434+
sourcePos(), from = `3.0`)
431435
true
432436
}
433437

compiler/src/dotty/tools/dotc/report.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ object report:
6868
if ctx.settings.YdebugTypeError.value then ex.printStackTrace()
6969

7070
def errorOrMigrationWarning(msg: Message, pos: SrcPos = NoSourcePosition,
71-
from: SourceVersion = SourceVersion.defaultSourceVersion)(using Context): Unit =
71+
from: SourceVersion)(using Context): Unit =
7272
if sourceVersion.isAtLeast(from) then
7373
if sourceVersion.isMigrating && sourceVersion.ordinal <= from.ordinal then migrationWarning(msg, pos)
7474
else error(msg, pos)
@@ -112,4 +112,4 @@ object report:
112112
case Nil => pos
113113
recur(pos.sourcePos, tpd.enclosingInlineds)
114114

115-
end report
115+
end report

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ object Checking {
117117
if tp.isUnreducibleWild then
118118
report.errorOrMigrationWarning(
119119
showInferred(UnreducibleApplication(tycon), tp, tpt),
120-
tree.srcPos)
120+
tree.srcPos, from = `3.0`)
121121
case _ =>
122122
}
123123
def checkValidIfApply(using Context): Unit =
@@ -189,7 +189,8 @@ object Checking {
189189
def checkRealizable(tp: Type, pos: SrcPos, what: String = "path")(using Context): Unit = {
190190
val rstatus = realizability(tp)
191191
if (rstatus ne Realizable)
192-
report.errorOrMigrationWarning(em"$tp is not a legal $what\nsince it${rstatus.msg}", pos)
192+
report.errorOrMigrationWarning(
193+
em"$tp is not a legal $what\nsince it${rstatus.msg}", pos, from = `3.0`)
193194
}
194195

195196
/** Given a parent `parent` of a class `cls`, if `parent` is a trait check that
@@ -641,7 +642,7 @@ object Checking {
641642
}
642643
val notPrivate = new NotPrivate
643644
val info = notPrivate(sym.info)
644-
notPrivate.errors.foreach(error => report.errorOrMigrationWarning(error(), sym.srcPos))
645+
notPrivate.errors.foreach(error => report.errorOrMigrationWarning(error(), sym.srcPos, from = `3.0`))
645646
info
646647
}
647648

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Decorators._
1616
import OverridingPairs.isOverridingPair
1717
import typer.ErrorReporting._
1818
import config.Feature.{warnOnMigration, migrateTo3}
19+
import config.SourceVersion.`3.0`
1920
import config.Printers.refcheck
2021
import reporting._
2122
import Constants.Constant
@@ -345,7 +346,7 @@ object RefChecks {
345346
isOverridingPair(member, memberTp, other, otherTp,
346347
fallBack = warnOnMigration(
347348
overrideErrorMsg("no longer has compatible type"),
348-
(if (member.owner == clazz) member else clazz).srcPos))
349+
(if (member.owner == clazz) member else clazz).srcPos, version = `3.0`))
349350
catch case ex: MissingType =>
350351
// can happen when called with upwardsSelf as qualifier of memberTp and otherTp,
351352
// because in that case we might access types that are not members of the qualifier.
@@ -453,7 +454,9 @@ object RefChecks {
453454
// Also excluded under Scala2 mode are overrides of default methods of Java traits.
454455
if (autoOverride(member) ||
455456
other.owner.isAllOf(JavaInterface) &&
456-
warnOnMigration("`override` modifier required when a Java 8 default method is re-implemented", member.srcPos))
457+
warnOnMigration(
458+
"`override` modifier required when a Java 8 default method is re-implemented",
459+
member.srcPos, version = `3.0`))
457460
member.setFlag(Override)
458461
else if (member.isType && self.memberInfo(member) =:= self.memberInfo(other))
459462
() // OK, don't complain about type aliases which are equal
@@ -484,7 +487,7 @@ object RefChecks {
484487
else if (member.is(ModuleVal) && !other.isRealMethod && !other.isOneOf(Deferred | Lazy))
485488
overrideError("may not override a concrete non-lazy value")
486489
else if (member.is(Lazy, butNot = Module) && !other.isRealMethod && !other.is(Lazy) &&
487-
!warnOnMigration(overrideErrorMsg("may not override a non-lazy value"), member.srcPos))
490+
!warnOnMigration(overrideErrorMsg("may not override a non-lazy value"), member.srcPos, version = `3.0`))
488491
overrideError("may not override a non-lazy value")
489492
else if (other.is(Lazy) && !other.isRealMethod && !member.is(Lazy))
490493
overrideError("must be declared lazy to override a lazy value")
@@ -769,7 +772,7 @@ object RefChecks {
769772
em"""${mbr.showLocated} is not a legal implementation of `$name` in $clazz
770773
| its type $mbrType
771774
| does not conform to ${mbrd.info}""",
772-
(if (mbr.owner == clazz) mbr else clazz).srcPos)
775+
(if (mbr.owner == clazz) mbr else clazz).srcPos, from = `3.0`)
773776
}
774777
}
775778

@@ -782,7 +785,7 @@ object RefChecks {
782785
for (baseCls <- caseCls.info.baseClasses.tail)
783786
if (baseCls.typeParams.exists(_.paramVarianceSign != 0))
784787
for (problem <- variantInheritanceProblems(baseCls, caseCls, "non-variant", "case "))
785-
report.errorOrMigrationWarning(problem(), clazz.srcPos)
788+
report.errorOrMigrationWarning(problem(), clazz.srcPos, from = `3.0`)
786789
checkNoAbstractMembers()
787790
if (abstractErrors.isEmpty)
788791
checkNoAbstractDecls(clazz)

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
385385
if !symsMatch && !suppressErrors then
386386
report.errorOrMigrationWarning(
387387
AmbiguousReference(name, Definition, Inheritance, prevCtx)(using outer),
388-
pos)
388+
pos, from = `3.0`)
389389
if migrateTo3 then
390390
patch(Span(pos.span.start),
391391
if prevCtx.owner == refctx.owner.enclosingClass then "this."
@@ -2661,7 +2661,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
26612661
case closure(_, _, _) =>
26622662
case _ =>
26632663
val recovered = typed(qual)(using ctx.fresh.setExploreTyperState())
2664-
report.errorOrMigrationWarning(OnlyFunctionsCanBeFollowedByUnderscore(recovered.tpe.widen), tree.srcPos)
2664+
report.errorOrMigrationWarning(OnlyFunctionsCanBeFollowedByUnderscore(recovered.tpe.widen), tree.srcPos, from = `3.0`)
26652665
if (migrateTo3) {
26662666
// Under -rewrite, patch `x _` to `(() => x)`
26672667
patch(Span(tree.span.start), "(() => ")
@@ -2813,7 +2813,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
28132813
then ", use `_` to denote a higher-kinded type parameter"
28142814
else ""
28152815
val namePos = tree.sourcePos.withSpan(tree.nameSpan)
2816-
report.errorOrMigrationWarning(s"`?` is not a valid type name$addendum", namePos)
2816+
report.errorOrMigrationWarning(
2817+
s"`?` is not a valid type name$addendum", namePos, from = `3.0`)
28172818
if tree.isClassDef then
28182819
typedClassDef(tree, sym.asClass)(using ctx.localContext(tree, sym))
28192820
else
@@ -3596,7 +3597,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
35963597
def isAutoApplied(sym: Symbol): Boolean =
35973598
sym.isConstructor
35983599
|| sym.matchNullaryLoosely
3599-
|| Feature.warnOnMigration(MissingEmptyArgumentList(sym.show), tree.srcPos)
3600+
|| Feature.warnOnMigration(MissingEmptyArgumentList(sym.show), tree.srcPos, version = `3.0`)
36003601
&& { patch(tree.span.endPos, "()"); true }
36013602

36023603
// Reasons NOT to eta expand:

0 commit comments

Comments
 (0)