Skip to content

Fix #6291: Rename Scala2 language setting to Scala2Compat #7540

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
Nov 15, 2019
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ object desugar {
ensureApplied(nu)
}

val copiedAccessFlags = if (ctx.scala2Setting) EmptyFlags else AccessFlags
val copiedAccessFlags = if (ctx.scala2CompatSetting) EmptyFlags else AccessFlags

// Methods to add to a case class C[..](p1: T1, ..., pN: Tn)(moreParams)
// def _1: T1 = this.p1
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ScalaSettings extends Settings.SettingGroup {
val pageWidth: Setting[Int] = IntSetting("-pagewidth", "Set page width", 80) withAbbreviation "--page-width"
val strict: Setting[Boolean] = BooleanSetting("-strict", "Use strict type rules, which means some formerly legal code does not typecheck anymore.") withAbbreviation "--strict"
val language: Setting[List[String]] = MultiStringSetting("-language", "feature", "Enable one or more language features.") withAbbreviation "--language"
val rewrite: Setting[Option[Rewrites]] = OptionSetting[Rewrites]("-rewrite", "When used in conjunction with -language:Scala2 rewrites sources to migrate to new syntax") withAbbreviation "--rewrite"
val rewrite: Setting[Option[Rewrites]] = OptionSetting[Rewrites]("-rewrite", "When used in conjunction with -language:Scala2Compat rewrites sources to migrate to new syntax") withAbbreviation "--rewrite"
val silentWarnings: Setting[Boolean] = BooleanSetting("-nowarn", "Silence all warnings.") withAbbreviation "--no-warnings"
val fromTasty: Setting[Boolean] = BooleanSetting("-from-tasty", "Compile classes from tasty in classpath. The arguments are used as class names.") withAbbreviation "--from-tasty"

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ object Denotations {
// things, starting with the return type of this method.
if (preferSym(sym2, sym1)) info2
else if (preferSym(sym1, sym2)) info1
else if (pre.widen.classSymbol.is(Scala2x) || ctx.scala2Mode)
else if (pre.widen.classSymbol.is(Scala2x) || ctx.scala2CompatMode)
info1 // follow Scala2 linearization -
// compare with way merge is performed in SymDenotation#computeMembersNamed
else throw new MergeError(ex.sym1, ex.sym2, ex.tp1, ex.tp2, pre)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ trait PatternTypeConstrainer { self: TypeComparer =>
}
}

val widePt = if (ctx.scala2Mode || refinementIsInvariant(patternTp)) scrutineeTp else widenVariantParams(scrutineeTp)
val widePt = if (ctx.scala2CompatMode || refinementIsInvariant(patternTp)) scrutineeTp else widenVariantParams(scrutineeTp)
val narrowTp = SkolemType(patternTp)
trace(i"constraining simple pattern type $narrowTp <:< $widePt", gadts, res => s"$res\ngadt = ${ctx.gadt.debugBoundsDescription}") {
isSubType(narrowTp, widePt)
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ object StdNames {
val RootPackage: N = "RootPackage"
val RootClass: N = "RootClass"
val Scala2: N = "Scala2"
val Scala2Compat: N = "Scala2Compat"
val Select: N = "Select"
val Shape: N = "Shape"
val StringContext: N = "StringContext"
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
* am not sure how, since the code is buried so deep in subtyping logic.
*/
def boundsOK =
ctx.scala2Mode ||
ctx.scala2CompatMode ||
tp1.typeParams.corresponds(tp2.typeParams)((tparam1, tparam2) =>
isSubType(tparam2.paramInfo.subst(tp2, tp1), tparam1.paramInfo))
val saved = comparedTypeLambdas
Expand Down Expand Up @@ -1730,7 +1730,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
/** The greatest lower bound of a list types */
final def glb(tps: List[Type]): Type = tps.foldLeft(AnyType: Type)(glb)

def widenInUnions(implicit ctx: Context): Boolean = ctx.scala2Mode || ctx.erasedTypes
def widenInUnions(implicit ctx: Context): Boolean = ctx.scala2CompatMode || ctx.erasedTypes

/** The least upper bound of two types
* @param canConstrain If true, new constraints might be added to simplify the lub.
Expand Down
27 changes: 18 additions & 9 deletions compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
* type parameter corresponding to the wildcard.
*/
def skolemizeWildcardArgs(tps: List[Type], app: Type) = app match {
case AppliedType(tycon, args) if tycon.typeSymbol.isClass && !scala2Mode =>
case AppliedType(tycon, args) if tycon.typeSymbol.isClass && !scala2CompatMode =>
tps.zipWithConserve(tycon.typeSymbol.typeParams) {
(tp, tparam) => tp match {
case _: TypeBounds => app.select(tparam)
Expand Down Expand Up @@ -500,25 +500,34 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
def canAutoTuple: Boolean =
!featureEnabled(nme.noAutoTupling)

def scala2Mode: Boolean =
featureEnabled(nme.Scala2)
def scala2CompatMode: Boolean =
featureEnabled(nme.Scala2Compat) || {
val scala2 = featureEnabled(nme.Scala2)
if scala2 then ctx.warning("Use `-language:Scala2Compat` or `import scala.Scala2Compat` instead of `-language:Scala2` or `import scala.Scala2`")
scala2
}


def dynamicsEnabled: Boolean =
featureEnabled(nme.dynamics)

def testScala2Mode(msg: => Message, pos: SourcePosition, replace: => Unit = ()): Boolean = {
if (scala2Mode) {
def testScala2CompatMode(msg: => Message, pos: SourcePosition, replace: => Unit = ()): Boolean = {
if (scala2CompatMode) {
migrationWarning(msg, pos)
replace
}
scala2Mode
scala2CompatMode
}

/** Is option -language:Scala2 set?
/** Is option -language:Scala2Compat set?
* This test is used when we are too early in the pipeline to consider imports.
*/
def scala2Setting: Boolean =
ctx.settings.language.value.contains(nme.Scala2.toString)
def scala2CompatSetting: Boolean =
ctx.settings.language.value.contains(nme.Scala2Compat.toString) || {
val scala2 = ctx.settings.language.value.contains(nme.Scala2.toString)
if scala2 then ctx.warning("Use -language:Scala2Compat instead of -language:Scala2")
scala2
}

/** Refine child based on parent
*
Expand Down
22 changes: 11 additions & 11 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,15 @@ object Parsers {
accept(SEMI)
}

/** Under -language:Scala2 or -old-syntax, flag
/** Under -language:Scala2Compat or -old-syntax, flag
*
* extends p1 with new p1 with t1 with
* p2 p2 t2
*
* as a migration warning or error since that means something else under significant indentation.
*/
def checkNotWithAtEOL(): Unit =
if (in.isScala2Mode || in.oldSyntax) && in.isAfterLineEnd then
if (in.isScala2CompatMode || in.oldSyntax) && in.isAfterLineEnd then
in.errorOrMigrationWarning("`with` cannot be followed by new line, place at beginning of next line instead")

def rewriteNotice(additionalOption: String = "") = {
Expand Down Expand Up @@ -446,7 +446,7 @@ object Parsers {
ts.map(convertToParam(_))
case t: Typed =>
in.errorOrMigrationWarning(
em"parentheses are required around the parameter of a lambda${rewriteNotice("-language:Scala2")}",
em"parentheses are required around the parameter of a lambda${rewriteNotice("-language:Scala2Compat")}",
t.span)
patch(source, t.span.startPos, "(")
patch(source, t.span.endPos, ")")
Expand Down Expand Up @@ -1180,7 +1180,7 @@ object Parsers {
in.errorOrMigrationWarning(em"""symbol literal '${in.name} is no longer supported,
|use a string literal "${in.name}" or an application Symbol("${in.name}") instead,
|or enclose in braces '{${in.name}} if you want a quoted expression.""")
if (in.isScala2Mode) {
if (in.isScala2CompatMode) {
patch(source, Span(in.offset, in.offset + 1), "Symbol(\"")
patch(source, Span(in.charOffset - 1), "\")")
}
Expand Down Expand Up @@ -1681,7 +1681,7 @@ object Parsers {
* the initially parsed (...) region?
*/
def toBeContinued(altToken: Token): Boolean =
if in.token == altToken || in.isNewLine || in.isScala2Mode then
if in.token == altToken || in.isNewLine || in.isScala2CompatMode then
false // a newline token means the expression is finished
else if !in.canStartStatTokens.contains(in.token)
|| in.isLeadingInfixOperator(inConditional = true)
Expand Down Expand Up @@ -1803,7 +1803,7 @@ object Parsers {
in.errorOrMigrationWarning(
i"""`do <body> while <cond>' is no longer supported,
|use `while ({<body> ; <cond>}) ()' instead.
|${rewriteNotice("-language:Scala2")}
|${rewriteNotice("-language:Scala2Compat")}
""")
val start = in.skipToken()
atSpan(start) {
Expand All @@ -1812,7 +1812,7 @@ object Parsers {
val whileStart = in.offset
accept(WHILE)
val cond = expr()
if (in.isScala2Mode) {
if (in.isScala2CompatMode) {
patch(source, Span(start, start + 2), "while ({")
patch(source, Span(whileStart, whileStart + 5), ";")
cond match {
Expand Down Expand Up @@ -2002,7 +2002,7 @@ object Parsers {
in.errorOrMigrationWarning(s"This syntax is no longer supported; parameter needs to be enclosed in (...)")
in.nextToken()
val t = infixType()
if (false && in.isScala2Mode) {
if (false && in.isScala2CompatMode) {
patch(source, Span(start), "(")
patch(source, Span(in.lastOffset), ")")
}
Expand Down Expand Up @@ -3106,7 +3106,7 @@ object Parsers {
val toInsert =
if (in.token == LBRACE) s"$resultTypeStr ="
else ": Unit " // trailing space ensures that `def f()def g()` works.
in.testScala2Mode(s"Procedure syntax no longer supported; `$toInsert' should be inserted here") && {
in.testScala2CompatMode(s"Procedure syntax no longer supported; `$toInsert' should be inserted here") && {
patch(source, Span(in.lastOffset), toInsert)
true
}
Expand All @@ -3120,7 +3120,7 @@ object Parsers {
case EOF => incompleteInputError(AuxConstructorNeedsNonImplicitParameter())
case _ => syntaxError(AuxConstructorNeedsNonImplicitParameter(), nameStart)
}
if (in.isScala2Mode) newLineOptWhenFollowedBy(LBRACE)
if (in.isScala2CompatMode) newLineOptWhenFollowedBy(LBRACE)
val rhs = {
if (!(in.token == LBRACE && scala2ProcedureSyntax(""))) accept(EQUALS)
atSpan(in.offset) { subPart(constrExpr) }
Expand Down Expand Up @@ -3159,7 +3159,7 @@ object Parsers {
TypeBoundsTree(EmptyTree, toplevelTyp())
else typedOpt()
}
if (in.isScala2Mode) newLineOptWhenFollowedBy(LBRACE)
if (in.isScala2CompatMode) newLineOptWhenFollowedBy(LBRACE)
val rhs =
if (in.token == EQUALS)
indentRegion(name) {
Expand Down
24 changes: 12 additions & 12 deletions compiler/src/dotty/tools/dotc/parsing/Scanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ object Scanners {
/** A switch whether operators at the start of lines can be infix operators */
private[Scanners] var allowLeadingInfixOperators = true

val isScala2Mode: Boolean = ctx.scala2Setting
val isScala2CompatMode: Boolean = ctx.scala2CompatSetting

val rewrite = ctx.settings.rewrite.value.isDefined
val oldSyntax = ctx.settings.oldSyntax.value
Expand All @@ -154,7 +154,7 @@ object Scanners {
val noindentSyntax =
ctx.settings.noindent.value
|| ctx.settings.oldSyntax.value
|| isScala2Mode
|| isScala2CompatMode
val indentSyntax =
(if (Config.defaultIndent) !noindentSyntax else ctx.settings.indent.value)
|| rewriteNoIndent
Expand Down Expand Up @@ -199,12 +199,12 @@ object Scanners {
private val commentBuf = new mutable.StringBuilder

private def handleMigration(keyword: Token): Token =
if (!isScala2Mode) keyword
if (!isScala2CompatMode) keyword
else if (scala3keywords.contains(keyword)) treatAsIdent()
else keyword

private def treatAsIdent() = {
testScala2Mode(i"$name is now a keyword, write `$name` instead of $name to keep it as an identifier")
testScala2CompatMode(i"$name is now a keyword, write `$name` instead of $name to keep it as an identifier")
patch(source, Span(offset), "`")
patch(source, Span(offset + name.length), "`")
IDENTIFIER
Expand Down Expand Up @@ -232,14 +232,14 @@ object Scanners {
// Scala 2 compatibility

/** Cannot use ctx.featureEnabled because accessing the context would force too much */
def testScala2Mode(msg: String, span: Span = Span(offset)): Boolean = {
if (isScala2Mode) ctx.migrationWarning(msg, source.atSpan(span))
isScala2Mode
def testScala2CompatMode(msg: String, span: Span = Span(offset)): Boolean = {
if (isScala2CompatMode) ctx.migrationWarning(msg, source.atSpan(span))
isScala2CompatMode
}

/** A migration warning if in Scala-2 mode, an error otherwise */
def errorOrMigrationWarning(msg: String, span: Span = Span(offset)): Unit =
if (isScala2Mode) ctx.migrationWarning(msg, source.atSpan(span))
if (isScala2CompatMode) ctx.migrationWarning(msg, source.atSpan(span))
else ctx.error(msg, source.atSpan(span))

// Get next token ------------------------------------------------------------
Expand Down Expand Up @@ -371,7 +371,7 @@ object Scanners {
* - it does not follow a blank line, and
* - it is followed on the same line by at least one ' '
* and a token that can start an expression.
* If a leading infix operator is found and -language:Scala2 or -old-syntax is set,
* If a leading infix operator is found and -language:Scala2Compat or -old-syntax is set,
* emit a change warning.
*/
def isLeadingInfixOperator(inConditional: Boolean = true) = (
Expand All @@ -388,7 +388,7 @@ object Scanners {
canStartExprTokens.contains(lookahead.token)
}
&& {
if isScala2Mode || oldSyntax && !rewrite then
if isScala2CompatMode || oldSyntax && !rewrite then
val (what, previous) =
if inConditional then ("Rest of line", "previous expression in parentheses")
else ("Line", "expression on the previous line")
Expand Down Expand Up @@ -1009,10 +1009,10 @@ object Scanners {
def isNestedEnd = token == RBRACE || token == OUTDENT

def canStartStatTokens =
if isScala2Mode then canStartStatTokens2 else canStartStatTokens3
if isScala2CompatMode then canStartStatTokens2 else canStartStatTokens3

def canStartExprTokens =
if isScala2Mode then canStartExprTokens2 else canStartExprTokens3
if isScala2CompatMode then canStartExprTokens2 else canStartExprTokens3

// Literals -----------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/reporting/Reporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ trait Reporting { this: Context =>
}

def errorOrMigrationWarning(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
if (ctx.scala2Mode) migrationWarning(msg, pos) else error(msg, pos)
if (ctx.scala2CompatMode) migrationWarning(msg, pos) else error(msg, pos)

def restrictionError(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
reporter.report {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1931,7 +1931,7 @@ object messages {
extends Message(UnapplyInvalidReturnTypeID) {
val kind = "Type Mismatch"
val addendum =
if (ctx.scala2Mode && unapplyName == nme.unapplySeq)
if (ctx.scala2CompatMode && unapplyName == nme.unapplySeq)
"\nYou might want to try to rewrite the extractor to use `unapply` instead."
else ""
val msg = em"""| ${Red(i"$unapplyResult")} is not a valid result type of an $unapplyName method of an ${Magenta("extractor")}.$addendum"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class NonLocalReturns extends MiniPhase {

override def transformReturn(tree: Return)(implicit ctx: Context): Tree =
if (isNonLocalReturn(tree)) {
if (!ctx.scala2Mode)
if (!ctx.scala2CompatMode)
ctx.strictWarning("Non local returns are deprecated; use scala.util.control.NonLocalReturns instead", tree.sourcePos)
nonLocalReturnThrow(tree.expr, tree.from.symbol).withSpan(tree.span)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ object ErrorReporting {
}

def rewriteNotice: String =
if (ctx.scala2Mode) "\nThis patch can be inserted automatically under -rewrite."
if (ctx.scala2CompatMode) "\nThis patch can be inserted automatically under -rewrite."
else ""
}

Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/typer/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ object Implicits {
// The reason for leaving out `Predef_conforms` is that we know it adds
// nothing since it only relates subtype with supertype.
//
// We keep the old behavior under -language:Scala2.
// We keep the old behavior under -language:Scala2Compat.
val isFunctionInS2 =
ctx.scala2Mode && tpw.derivesFrom(defn.FunctionClass(1)) && ref.symbol != defn.Predef_conforms
ctx.scala2CompatMode && tpw.derivesFrom(defn.FunctionClass(1)) && ref.symbol != defn.Predef_conforms
val isImplicitConversion = tpw.derivesFrom(defn.ConversionClass)
// An implementation of <:< counts as a view
val isConforms = tpw.derivesFrom(defn.SubTypeClass)
Expand Down Expand Up @@ -265,7 +265,7 @@ object Implicits {
*/
override val level: Int =
if (outerImplicits == null) 1
else if (ctx.scala2Mode ||
else if (ctx.scala2CompatMode ||
(ctx.owner eq outerImplicits.ctx.owner) &&
(ctx.scope eq outerImplicits.ctx.scope) &&
!refs.head.implicitName.is(LazyImplicitName)) outerImplicits.level
Expand Down Expand Up @@ -567,7 +567,7 @@ trait ImplicitRunInfo {
addPath(pre.cls.sourceModule.termRef)
case pre: TermRef =>
if (pre.symbol.is(Package)) {
if (ctx.scala2Mode) {
if (ctx.scala2CompatMode) {
addCompanion(pre, pre.member(nme.PACKAGE).symbol)
addPath(pre.prefix)
}
Expand Down Expand Up @@ -1323,7 +1323,7 @@ trait Implicits { self: Typer =>
case result: SearchFailure if result.isAmbiguous =>
val deepPt = pt.deepenProto
if (deepPt ne pt) inferImplicit(deepPt, argument, span)
else if (ctx.scala2Mode && !ctx.mode.is(Mode.OldOverloadingResolution))
else if (ctx.scala2CompatMode && !ctx.mode.is(Mode.OldOverloadingResolution))
inferImplicit(pt, argument, span)(ctx.addMode(Mode.OldOverloadingResolution)) match {
case altResult: SearchSuccess =>
ctx.migrationWarning(
Expand Down Expand Up @@ -1502,7 +1502,7 @@ trait Implicits { self: Typer =>
negateIfNot(tryImplicit(cand, contextual)) match {
case fail: SearchFailure =>
if (fail.isAmbiguous)
if (ctx.scala2Mode) {
if (ctx.scala2CompatMode) {
val result = rank(remaining, found, NoMatchingImplicitsFailure :: rfailures)
if (result.isSuccess)
warnAmbiguousNegation(fail.reason.asInstanceOf[AmbiguousImplicits])
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ class Namer { typer: Typer =>
traitReq = parent ne parents.head, stablePrefixReq = true)
if (pt.derivesFrom(cls)) {
val addendum = parent match {
case Select(qual: Super, _) if ctx.scala2Mode =>
case Select(qual: Super, _) if ctx.scala2CompatMode =>
"\n(Note that inheriting a class of the same name is no longer allowed)"
case _ => ""
}
Expand Down
Loading