Skip to content

Commit ca6b1c6

Browse files
Merge pull request #7540 from dotty-staging/fix-#6291
Fix #6291: Rename Scala2 language setting to Scala2Compat
2 parents 68375c9 + 6e4966c commit ca6b1c6

File tree

150 files changed

+209
-199
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

150 files changed

+209
-199
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ object desugar {
576576
ensureApplied(nu)
577577
}
578578

579-
val copiedAccessFlags = if (ctx.scala2Setting) EmptyFlags else AccessFlags
579+
val copiedAccessFlags = if (ctx.scala2CompatSetting) EmptyFlags else AccessFlags
580580

581581
// Methods to add to a case class C[..](p1: T1, ..., pN: Tn)(moreParams)
582582
// def _1: T1 = this.p1

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ScalaSettings extends Settings.SettingGroup {
4444
val pageWidth: Setting[Int] = IntSetting("-pagewidth", "Set page width", 80) withAbbreviation "--page-width"
4545
val strict: Setting[Boolean] = BooleanSetting("-strict", "Use strict type rules, which means some formerly legal code does not typecheck anymore.") withAbbreviation "--strict"
4646
val language: Setting[List[String]] = MultiStringSetting("-language", "feature", "Enable one or more language features.") withAbbreviation "--language"
47-
val rewrite: Setting[Option[Rewrites]] = OptionSetting[Rewrites]("-rewrite", "When used in conjunction with -language:Scala2 rewrites sources to migrate to new syntax") withAbbreviation "--rewrite"
47+
val rewrite: Setting[Option[Rewrites]] = OptionSetting[Rewrites]("-rewrite", "When used in conjunction with -language:Scala2Compat rewrites sources to migrate to new syntax") withAbbreviation "--rewrite"
4848
val silentWarnings: Setting[Boolean] = BooleanSetting("-nowarn", "Silence all warnings.") withAbbreviation "--no-warnings"
4949
val fromTasty: Setting[Boolean] = BooleanSetting("-from-tasty", "Compile classes from tasty in classpath. The arguments are used as class names.") withAbbreviation "--from-tasty"
5050

compiler/src/dotty/tools/dotc/core/Denotations.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ object Denotations {
486486
// things, starting with the return type of this method.
487487
if (preferSym(sym2, sym1)) info2
488488
else if (preferSym(sym1, sym2)) info1
489-
else if (pre.widen.classSymbol.is(Scala2x) || ctx.scala2Mode)
489+
else if (pre.widen.classSymbol.is(Scala2x) || ctx.scala2CompatMode)
490490
info1 // follow Scala2 linearization -
491491
// compare with way merge is performed in SymDenotation#computeMembersNamed
492492
else throw new MergeError(ex.sym1, ex.sym2, ex.tp1, ex.tp2, pre)

compiler/src/dotty/tools/dotc/core/PatternTypeConstrainer.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ trait PatternTypeConstrainer { self: TypeComparer =>
199199
}
200200
}
201201

202-
val widePt = if (ctx.scala2Mode || refinementIsInvariant(patternTp)) scrutineeTp else widenVariantParams(scrutineeTp)
202+
val widePt = if (ctx.scala2CompatMode || refinementIsInvariant(patternTp)) scrutineeTp else widenVariantParams(scrutineeTp)
203203
val narrowTp = SkolemType(patternTp)
204204
trace(i"constraining simple pattern type $narrowTp <:< $widePt", gadts, res => s"$res\ngadt = ${ctx.gadt.debugBoundsDescription}") {
205205
isSubType(narrowTp, widePt)

compiler/src/dotty/tools/dotc/core/StdNames.scala

+1
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ object StdNames {
359359
val RootPackage: N = "RootPackage"
360360
val RootClass: N = "RootClass"
361361
val Scala2: N = "Scala2"
362+
val Scala2Compat: N = "Scala2Compat"
362363
val Select: N = "Select"
363364
val Shape: N = "Shape"
364365
val StringContext: N = "StringContext"

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
573573
* am not sure how, since the code is buried so deep in subtyping logic.
574574
*/
575575
def boundsOK =
576-
ctx.scala2Mode ||
576+
ctx.scala2CompatMode ||
577577
tp1.typeParams.corresponds(tp2.typeParams)((tparam1, tparam2) =>
578578
isSubType(tparam2.paramInfo.subst(tp2, tp1), tparam1.paramInfo))
579579
val saved = comparedTypeLambdas
@@ -1730,7 +1730,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
17301730
/** The greatest lower bound of a list types */
17311731
final def glb(tps: List[Type]): Type = tps.foldLeft(AnyType: Type)(glb)
17321732

1733-
def widenInUnions(implicit ctx: Context): Boolean = ctx.scala2Mode || ctx.erasedTypes
1733+
def widenInUnions(implicit ctx: Context): Boolean = ctx.scala2CompatMode || ctx.erasedTypes
17341734

17351735
/** The least upper bound of two types
17361736
* @param canConstrain If true, new constraints might be added to simplify the lub.

compiler/src/dotty/tools/dotc/core/TypeOps.scala

+18-9
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
369369
* type parameter corresponding to the wildcard.
370370
*/
371371
def skolemizeWildcardArgs(tps: List[Type], app: Type) = app match {
372-
case AppliedType(tycon, args) if tycon.typeSymbol.isClass && !scala2Mode =>
372+
case AppliedType(tycon, args) if tycon.typeSymbol.isClass && !scala2CompatMode =>
373373
tps.zipWithConserve(tycon.typeSymbol.typeParams) {
374374
(tp, tparam) => tp match {
375375
case _: TypeBounds => app.select(tparam)
@@ -500,25 +500,34 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
500500
def canAutoTuple: Boolean =
501501
!featureEnabled(nme.noAutoTupling)
502502

503-
def scala2Mode: Boolean =
504-
featureEnabled(nme.Scala2)
503+
def scala2CompatMode: Boolean =
504+
featureEnabled(nme.Scala2Compat) || {
505+
val scala2 = featureEnabled(nme.Scala2)
506+
if scala2 then ctx.warning("Use `-language:Scala2Compat` or `import scala.Scala2Compat` instead of `-language:Scala2` or `import scala.Scala2`")
507+
scala2
508+
}
509+
505510

506511
def dynamicsEnabled: Boolean =
507512
featureEnabled(nme.dynamics)
508513

509-
def testScala2Mode(msg: => Message, pos: SourcePosition, replace: => Unit = ()): Boolean = {
510-
if (scala2Mode) {
514+
def testScala2CompatMode(msg: => Message, pos: SourcePosition, replace: => Unit = ()): Boolean = {
515+
if (scala2CompatMode) {
511516
migrationWarning(msg, pos)
512517
replace
513518
}
514-
scala2Mode
519+
scala2CompatMode
515520
}
516521

517-
/** Is option -language:Scala2 set?
522+
/** Is option -language:Scala2Compat set?
518523
* This test is used when we are too early in the pipeline to consider imports.
519524
*/
520-
def scala2Setting: Boolean =
521-
ctx.settings.language.value.contains(nme.Scala2.toString)
525+
def scala2CompatSetting: Boolean =
526+
ctx.settings.language.value.contains(nme.Scala2Compat.toString) || {
527+
val scala2 = ctx.settings.language.value.contains(nme.Scala2.toString)
528+
if scala2 then ctx.warning("Use -language:Scala2Compat instead of -language:Scala2")
529+
scala2
530+
}
522531

523532
/** Refine child based on parent
524533
*

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -361,15 +361,15 @@ object Parsers {
361361
accept(SEMI)
362362
}
363363

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

375375
def rewriteNotice(additionalOption: String = "") = {
@@ -446,7 +446,7 @@ object Parsers {
446446
ts.map(convertToParam(_))
447447
case t: Typed =>
448448
in.errorOrMigrationWarning(
449-
em"parentheses are required around the parameter of a lambda${rewriteNotice("-language:Scala2")}",
449+
em"parentheses are required around the parameter of a lambda${rewriteNotice("-language:Scala2Compat")}",
450450
t.span)
451451
patch(source, t.span.startPos, "(")
452452
patch(source, t.span.endPos, ")")
@@ -1180,7 +1180,7 @@ object Parsers {
11801180
in.errorOrMigrationWarning(em"""symbol literal '${in.name} is no longer supported,
11811181
|use a string literal "${in.name}" or an application Symbol("${in.name}") instead,
11821182
|or enclose in braces '{${in.name}} if you want a quoted expression.""")
1183-
if (in.isScala2Mode) {
1183+
if (in.isScala2CompatMode) {
11841184
patch(source, Span(in.offset, in.offset + 1), "Symbol(\"")
11851185
patch(source, Span(in.charOffset - 1), "\")")
11861186
}
@@ -1681,7 +1681,7 @@ object Parsers {
16811681
* the initially parsed (...) region?
16821682
*/
16831683
def toBeContinued(altToken: Token): Boolean =
1684-
if in.token == altToken || in.isNewLine || in.isScala2Mode then
1684+
if in.token == altToken || in.isNewLine || in.isScala2CompatMode then
16851685
false // a newline token means the expression is finished
16861686
else if !in.canStartStatTokens.contains(in.token)
16871687
|| in.isLeadingInfixOperator(inConditional = true)
@@ -1803,7 +1803,7 @@ object Parsers {
18031803
in.errorOrMigrationWarning(
18041804
i"""`do <body> while <cond>' is no longer supported,
18051805
|use `while ({<body> ; <cond>}) ()' instead.
1806-
|${rewriteNotice("-language:Scala2")}
1806+
|${rewriteNotice("-language:Scala2Compat")}
18071807
""")
18081808
val start = in.skipToken()
18091809
atSpan(start) {
@@ -1812,7 +1812,7 @@ object Parsers {
18121812
val whileStart = in.offset
18131813
accept(WHILE)
18141814
val cond = expr()
1815-
if (in.isScala2Mode) {
1815+
if (in.isScala2CompatMode) {
18161816
patch(source, Span(start, start + 2), "while ({")
18171817
patch(source, Span(whileStart, whileStart + 5), ";")
18181818
cond match {
@@ -2002,7 +2002,7 @@ object Parsers {
20022002
in.errorOrMigrationWarning(s"This syntax is no longer supported; parameter needs to be enclosed in (...)")
20032003
in.nextToken()
20042004
val t = infixType()
2005-
if (false && in.isScala2Mode) {
2005+
if (false && in.isScala2CompatMode) {
20062006
patch(source, Span(start), "(")
20072007
patch(source, Span(in.lastOffset), ")")
20082008
}
@@ -3106,7 +3106,7 @@ object Parsers {
31063106
val toInsert =
31073107
if (in.token == LBRACE) s"$resultTypeStr ="
31083108
else ": Unit " // trailing space ensures that `def f()def g()` works.
3109-
in.testScala2Mode(s"Procedure syntax no longer supported; `$toInsert' should be inserted here") && {
3109+
in.testScala2CompatMode(s"Procedure syntax no longer supported; `$toInsert' should be inserted here") && {
31103110
patch(source, Span(in.lastOffset), toInsert)
31113111
true
31123112
}
@@ -3120,7 +3120,7 @@ object Parsers {
31203120
case EOF => incompleteInputError(AuxConstructorNeedsNonImplicitParameter())
31213121
case _ => syntaxError(AuxConstructorNeedsNonImplicitParameter(), nameStart)
31223122
}
3123-
if (in.isScala2Mode) newLineOptWhenFollowedBy(LBRACE)
3123+
if (in.isScala2CompatMode) newLineOptWhenFollowedBy(LBRACE)
31243124
val rhs = {
31253125
if (!(in.token == LBRACE && scala2ProcedureSyntax(""))) accept(EQUALS)
31263126
atSpan(in.offset) { subPart(constrExpr) }
@@ -3159,7 +3159,7 @@ object Parsers {
31593159
TypeBoundsTree(EmptyTree, toplevelTyp())
31603160
else typedOpt()
31613161
}
3162-
if (in.isScala2Mode) newLineOptWhenFollowedBy(LBRACE)
3162+
if (in.isScala2CompatMode) newLineOptWhenFollowedBy(LBRACE)
31633163
val rhs =
31643164
if (in.token == EQUALS)
31653165
indentRegion(name) {

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

+12-12
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ object Scanners {
142142
/** A switch whether operators at the start of lines can be infix operators */
143143
private[Scanners] var allowLeadingInfixOperators = true
144144

145-
val isScala2Mode: Boolean = ctx.scala2Setting
145+
val isScala2CompatMode: Boolean = ctx.scala2CompatSetting
146146

147147
val rewrite = ctx.settings.rewrite.value.isDefined
148148
val oldSyntax = ctx.settings.oldSyntax.value
@@ -154,7 +154,7 @@ object Scanners {
154154
val noindentSyntax =
155155
ctx.settings.noindent.value
156156
|| ctx.settings.oldSyntax.value
157-
|| isScala2Mode
157+
|| isScala2CompatMode
158158
val indentSyntax =
159159
(if (Config.defaultIndent) !noindentSyntax else ctx.settings.indent.value)
160160
|| rewriteNoIndent
@@ -199,12 +199,12 @@ object Scanners {
199199
private val commentBuf = new mutable.StringBuilder
200200

201201
private def handleMigration(keyword: Token): Token =
202-
if (!isScala2Mode) keyword
202+
if (!isScala2CompatMode) keyword
203203
else if (scala3keywords.contains(keyword)) treatAsIdent()
204204
else keyword
205205

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

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

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

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

10111011
def canStartStatTokens =
1012-
if isScala2Mode then canStartStatTokens2 else canStartStatTokens3
1012+
if isScala2CompatMode then canStartStatTokens2 else canStartStatTokens3
10131013

10141014
def canStartExprTokens =
1015-
if isScala2Mode then canStartExprTokens2 else canStartExprTokens3
1015+
if isScala2CompatMode then canStartExprTokens2 else canStartExprTokens3
10161016

10171017
// Literals -----------------------------------------------------------------
10181018

compiler/src/dotty/tools/dotc/reporting/Reporter.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ trait Reporting { this: Context =>
144144
}
145145

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

149149
def restrictionError(msg: => Message, pos: SourcePosition = NoSourcePosition): Unit =
150150
reporter.report {

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1931,7 +1931,7 @@ object messages {
19311931
extends Message(UnapplyInvalidReturnTypeID) {
19321932
val kind = "Type Mismatch"
19331933
val addendum =
1934-
if (ctx.scala2Mode && unapplyName == nme.unapplySeq)
1934+
if (ctx.scala2CompatMode && unapplyName == nme.unapplySeq)
19351935
"\nYou might want to try to rewrite the extractor to use `unapply` instead."
19361936
else ""
19371937
val msg = em"""| ${Red(i"$unapplyResult")} is not a valid result type of an $unapplyName method of an ${Magenta("extractor")}.$addendum"""

compiler/src/dotty/tools/dotc/transform/NonLocalReturns.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class NonLocalReturns extends MiniPhase {
8888

8989
override def transformReturn(tree: Return)(implicit ctx: Context): Tree =
9090
if (isNonLocalReturn(tree)) {
91-
if (!ctx.scala2Mode)
91+
if (!ctx.scala2CompatMode)
9292
ctx.strictWarning("Non local returns are deprecated; use scala.util.control.NonLocalReturns instead", tree.sourcePos)
9393
nonLocalReturnThrow(tree.expr, tree.from.symbol).withSpan(tree.span)
9494
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ object ErrorReporting {
167167
}
168168

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

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ object Implicits {
141141
// The reason for leaving out `Predef_conforms` is that we know it adds
142142
// nothing since it only relates subtype with supertype.
143143
//
144-
// We keep the old behavior under -language:Scala2.
144+
// We keep the old behavior under -language:Scala2Compat.
145145
val isFunctionInS2 =
146-
ctx.scala2Mode && tpw.derivesFrom(defn.FunctionClass(1)) && ref.symbol != defn.Predef_conforms
146+
ctx.scala2CompatMode && tpw.derivesFrom(defn.FunctionClass(1)) && ref.symbol != defn.Predef_conforms
147147
val isImplicitConversion = tpw.derivesFrom(defn.ConversionClass)
148148
// An implementation of <:< counts as a view
149149
val isConforms = tpw.derivesFrom(defn.SubTypeClass)
@@ -265,7 +265,7 @@ object Implicits {
265265
*/
266266
override val level: Int =
267267
if (outerImplicits == null) 1
268-
else if (ctx.scala2Mode ||
268+
else if (ctx.scala2CompatMode ||
269269
(ctx.owner eq outerImplicits.ctx.owner) &&
270270
(ctx.scope eq outerImplicits.ctx.scope) &&
271271
!refs.head.implicitName.is(LazyImplicitName)) outerImplicits.level
@@ -567,7 +567,7 @@ trait ImplicitRunInfo {
567567
addPath(pre.cls.sourceModule.termRef)
568568
case pre: TermRef =>
569569
if (pre.symbol.is(Package)) {
570-
if (ctx.scala2Mode) {
570+
if (ctx.scala2CompatMode) {
571571
addCompanion(pre, pre.member(nme.PACKAGE).symbol)
572572
addPath(pre.prefix)
573573
}
@@ -1323,7 +1323,7 @@ trait Implicits { self: Typer =>
13231323
case result: SearchFailure if result.isAmbiguous =>
13241324
val deepPt = pt.deepenProto
13251325
if (deepPt ne pt) inferImplicit(deepPt, argument, span)
1326-
else if (ctx.scala2Mode && !ctx.mode.is(Mode.OldOverloadingResolution))
1326+
else if (ctx.scala2CompatMode && !ctx.mode.is(Mode.OldOverloadingResolution))
13271327
inferImplicit(pt, argument, span)(ctx.addMode(Mode.OldOverloadingResolution)) match {
13281328
case altResult: SearchSuccess =>
13291329
ctx.migrationWarning(
@@ -1502,7 +1502,7 @@ trait Implicits { self: Typer =>
15021502
negateIfNot(tryImplicit(cand, contextual)) match {
15031503
case fail: SearchFailure =>
15041504
if (fail.isAmbiguous)
1505-
if (ctx.scala2Mode) {
1505+
if (ctx.scala2CompatMode) {
15061506
val result = rank(remaining, found, NoMatchingImplicitsFailure :: rfailures)
15071507
if (result.isSuccess)
15081508
warnAmbiguousNegation(fail.reason.asInstanceOf[AmbiguousImplicits])

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ class Namer { typer: Typer =>
11531153
traitReq = parent ne parents.head, stablePrefixReq = true)
11541154
if (pt.derivesFrom(cls)) {
11551155
val addendum = parent match {
1156-
case Select(qual: Super, _) if ctx.scala2Mode =>
1156+
case Select(qual: Super, _) if ctx.scala2CompatMode =>
11571157
"\n(Note that inheriting a class of the same name is no longer allowed)"
11581158
case _ => ""
11591159
}

0 commit comments

Comments
 (0)