Skip to content

add 3.2 language mode internally, treat it like 3.0, 3.1 #14690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/config/Feature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ object Feature:
* and return `true`, otherwise return `false`.
*/
def warnOnMigration(msg: Message, pos: SrcPos,
version: SourceVersion = defaultSourceVersion)(using Context): Boolean =
version: SourceVersion)(using Context): Boolean =
if sourceVersion.isMigrating && sourceVersion.stable == version
|| (version == `3.0` || version == `3.1`) && migrateTo3
|| (version == `3.0` || version == `3.1` || version == `3.2`) && migrateTo3
then
report.migrationWarning(msg, pos)
true
Expand Down
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/config/SourceVersion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import core.Decorators.*
import util.Property

enum SourceVersion:
case `3.0-migration`, `3.0`, `3.1`, `future-migration`, `future`
case `3.0-migration`, `3.0`, `3.1`, `3.2`, `future-migration`, `future`

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

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

object SourceVersion extends Property.Key[SourceVersion]:
def defaultSourceVersion = `3.0`

val allSourceVersionNames = values.toList.map(_.toString.toTermName)
end SourceVersion
16 changes: 8 additions & 8 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ object Parsers {
case t: Typed =>
report.errorOrMigrationWarning(
em"parentheses are required around the parameter of a lambda${rewriteNotice()}",
in.sourcePos())
in.sourcePos(), from = `3.0`)
if migrateTo3 then
patch(source, t.span.startPos, "(")
patch(source, t.span.endPos, ")")
Expand Down Expand Up @@ -1180,7 +1180,7 @@ object Parsers {
|or enclose in braces '{$name} if you want a quoted expression.
|For now, you can also `import language.deprecated.symbolLiterals` to accept
|the idiom, but this possibility might no longer be available in the future.""",
in.sourcePos())
in.sourcePos(), from = `3.0`)
if migrateTo3 then
patch(source, Span(in.offset, in.offset + 1), "Symbol(\"")
patch(source, Span(in.charOffset - 1), "\")")
Expand Down Expand Up @@ -1272,7 +1272,7 @@ object Parsers {
i"""This opening brace will start a new statement in Scala 3.
|It needs to be indented to the right to keep being treated as
|an argument to the previous expression.${rewriteNotice()}""",
in.sourcePos())
in.sourcePos(), from = `3.0`)
patch(source, Span(in.offset), " ")

def possibleTemplateStart(isNew: Boolean = false): Unit =
Expand Down Expand Up @@ -1826,7 +1826,7 @@ object Parsers {
else if in.token == VIEWBOUND then
report.errorOrMigrationWarning(
"view bounds `<%' are no longer supported, use a context bound `:' instead",
in.sourcePos())
in.sourcePos(), from = `3.0`)
atSpan(in.skipToken()) {
Function(Ident(pname) :: Nil, toplevelTyp())
} :: contextBounds(pname)
Expand Down Expand Up @@ -1976,7 +1976,7 @@ object Parsers {
report.errorOrMigrationWarning(
i"""`do <body> while <cond>` is no longer supported,
|use `while <body> ; <cond> do ()` instead.${rewriteNotice()}""",
in.sourcePos())
in.sourcePos(), from = `3.0`)
val start = in.skipToken()
atSpan(start) {
val body = expr()
Expand Down Expand Up @@ -2096,7 +2096,7 @@ object Parsers {
report.errorOrMigrationWarning(
em"""`_*` can be used only for last argument of method application.
|It is no longer allowed in operands of infix operations.""",
in.sourcePos(uscoreStart))
in.sourcePos(uscoreStart), from = `3.0`)
else
syntaxError(SeqWildcardPatternPos(), uscoreStart)
Typed(t, atSpan(uscoreStart) { Ident(tpnme.WILDCARD_STAR) })
Expand Down Expand Up @@ -3347,7 +3347,7 @@ object Parsers {
if migrateTo3 then
report.errorOrMigrationWarning(
s"Procedure syntax no longer supported; `$toInsert` should be inserted here",
in.sourcePos())
in.sourcePos(), from = `3.0`)
patch(source, Span(in.lastOffset), toInsert)
true
else
Expand Down Expand Up @@ -3756,7 +3756,7 @@ object Parsers {
if (in.token == LBRACE || in.token == COLONEOL) {
report.errorOrMigrationWarning(
"`extends` must be followed by at least one parent",
in.sourcePos())
in.sourcePos(), from = `3.0`)
Nil
}
else constrApps()
Expand Down
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import scala.collection.immutable.SortedMap
import rewrites.Rewrites.patch
import config.Feature
import config.Feature.migrateTo3
import config.SourceVersion.`3.0`

object Scanners {

Expand Down Expand Up @@ -255,7 +256,10 @@ object Scanners {
def handleMigration(keyword: Token): Token =
if scala3keywords.contains(keyword) && migrateTo3 then
val what = tokenString(keyword)
report.errorOrMigrationWarning(i"$what is now a keyword, write `$what` instead of $what to keep it as an identifier", sourcePos())
report.errorOrMigrationWarning(
i"$what is now a keyword, write `$what` instead of $what to keep it as an identifier",
sourcePos(),
from = `3.0`)
patch(source, Span(offset), "`")
patch(source, Span(offset + identifier.length), "`")
IDENTIFIER
Expand Down Expand Up @@ -427,7 +431,7 @@ object Scanners {
em"""$what starts with an operator;
|it is now treated as a continuation of the $previous,
|not as a separate statement.""",
sourcePos())
sourcePos(), from = `3.0`)
true
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ object report:
if ctx.settings.YdebugTypeError.value then ex.printStackTrace()

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

end report
end report
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ object Checking {
if tp.isUnreducibleWild then
report.errorOrMigrationWarning(
showInferred(UnreducibleApplication(tycon), tp, tpt),
tree.srcPos)
tree.srcPos, from = `3.0`)
case _ =>
}
def checkValidIfApply(using Context): Unit =
Expand Down Expand Up @@ -189,7 +189,8 @@ object Checking {
def checkRealizable(tp: Type, pos: SrcPos, what: String = "path")(using Context): Unit = {
val rstatus = realizability(tp)
if (rstatus ne Realizable)
report.errorOrMigrationWarning(em"$tp is not a legal $what\nsince it${rstatus.msg}", pos)
report.errorOrMigrationWarning(
em"$tp is not a legal $what\nsince it${rstatus.msg}", pos, from = `3.0`)
}

/** Given a parent `parent` of a class `cls`, if `parent` is a trait check that
Expand Down Expand Up @@ -641,7 +642,7 @@ object Checking {
}
val notPrivate = new NotPrivate
val info = notPrivate(sym.info)
notPrivate.errors.foreach(error => report.errorOrMigrationWarning(error(), sym.srcPos))
notPrivate.errors.foreach(error => report.errorOrMigrationWarning(error(), sym.srcPos, from = `3.0`))
info
}

Expand Down
13 changes: 8 additions & 5 deletions compiler/src/dotty/tools/dotc/typer/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Decorators._
import OverridingPairs.isOverridingPair
import typer.ErrorReporting._
import config.Feature.{warnOnMigration, migrateTo3}
import config.SourceVersion.`3.0`
import config.Printers.refcheck
import reporting._
import Constants.Constant
Expand Down Expand Up @@ -345,7 +346,7 @@ object RefChecks {
isOverridingPair(member, memberTp, other, otherTp,
fallBack = warnOnMigration(
overrideErrorMsg("no longer has compatible type"),
(if (member.owner == clazz) member else clazz).srcPos))
(if (member.owner == clazz) member else clazz).srcPos, version = `3.0`))
catch case ex: MissingType =>
// can happen when called with upwardsSelf as qualifier of memberTp and otherTp,
// because in that case we might access types that are not members of the qualifier.
Expand Down Expand Up @@ -453,7 +454,9 @@ object RefChecks {
// Also excluded under Scala2 mode are overrides of default methods of Java traits.
if (autoOverride(member) ||
other.owner.isAllOf(JavaInterface) &&
warnOnMigration("`override` modifier required when a Java 8 default method is re-implemented", member.srcPos))
warnOnMigration(
"`override` modifier required when a Java 8 default method is re-implemented",
member.srcPos, version = `3.0`))
member.setFlag(Override)
else if (member.isType && self.memberInfo(member) =:= self.memberInfo(other))
() // OK, don't complain about type aliases which are equal
Expand Down Expand Up @@ -484,7 +487,7 @@ object RefChecks {
else if (member.is(ModuleVal) && !other.isRealMethod && !other.isOneOf(Deferred | Lazy))
overrideError("may not override a concrete non-lazy value")
else if (member.is(Lazy, butNot = Module) && !other.isRealMethod && !other.is(Lazy) &&
!warnOnMigration(overrideErrorMsg("may not override a non-lazy value"), member.srcPos))
!warnOnMigration(overrideErrorMsg("may not override a non-lazy value"), member.srcPos, version = `3.0`))
overrideError("may not override a non-lazy value")
else if (other.is(Lazy) && !other.isRealMethod && !member.is(Lazy))
overrideError("must be declared lazy to override a lazy value")
Expand Down Expand Up @@ -769,7 +772,7 @@ object RefChecks {
em"""${mbr.showLocated} is not a legal implementation of `$name` in $clazz
| its type $mbrType
| does not conform to ${mbrd.info}""",
(if (mbr.owner == clazz) mbr else clazz).srcPos)
(if (mbr.owner == clazz) mbr else clazz).srcPos, from = `3.0`)
}
}

Expand All @@ -782,7 +785,7 @@ object RefChecks {
for (baseCls <- caseCls.info.baseClasses.tail)
if (baseCls.typeParams.exists(_.paramVarianceSign != 0))
for (problem <- variantInheritanceProblems(baseCls, caseCls, "non-variant", "case "))
report.errorOrMigrationWarning(problem(), clazz.srcPos)
report.errorOrMigrationWarning(problem(), clazz.srcPos, from = `3.0`)
checkNoAbstractMembers()
if (abstractErrors.isEmpty)
checkNoAbstractDecls(clazz)
Expand Down
9 changes: 5 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
if !symsMatch && !suppressErrors then
report.errorOrMigrationWarning(
AmbiguousReference(name, Definition, Inheritance, prevCtx)(using outer),
pos)
pos, from = `3.0`)
if migrateTo3 then
patch(Span(pos.span.start),
if prevCtx.owner == refctx.owner.enclosingClass then "this."
Expand Down Expand Up @@ -2661,7 +2661,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
case closure(_, _, _) =>
case _ =>
val recovered = typed(qual)(using ctx.fresh.setExploreTyperState())
report.errorOrMigrationWarning(OnlyFunctionsCanBeFollowedByUnderscore(recovered.tpe.widen), tree.srcPos)
report.errorOrMigrationWarning(OnlyFunctionsCanBeFollowedByUnderscore(recovered.tpe.widen), tree.srcPos, from = `3.0`)
if (migrateTo3) {
// Under -rewrite, patch `x _` to `(() => x)`
patch(Span(tree.span.start), "(() => ")
Expand Down Expand Up @@ -2813,7 +2813,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
then ", use `_` to denote a higher-kinded type parameter"
else ""
val namePos = tree.sourcePos.withSpan(tree.nameSpan)
report.errorOrMigrationWarning(s"`?` is not a valid type name$addendum", namePos)
report.errorOrMigrationWarning(
s"`?` is not a valid type name$addendum", namePos, from = `3.0`)
if tree.isClassDef then
typedClassDef(tree, sym.asClass)(using ctx.localContext(tree, sym))
else
Expand Down Expand Up @@ -3596,7 +3597,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
def isAutoApplied(sym: Symbol): Boolean =
sym.isConstructor
|| sym.matchNullaryLoosely
|| Feature.warnOnMigration(MissingEmptyArgumentList(sym.show), tree.srcPos)
|| Feature.warnOnMigration(MissingEmptyArgumentList(sym.show), tree.srcPos, version = `3.0`)
&& { patch(tree.span.endPos, "()"); true }

// Reasons NOT to eta expand:
Expand Down