Skip to content

Commit 6b840fc

Browse files
committed
Keep old scheme if option -language:Scala2 is set.
1 parent d657bd7 commit 6b840fc

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ object desugar {
430430
// new C[Ts](paramss)
431431
lazy val creatorExpr = New(classTypeRef, constrVparamss nestedMap refOfDef)
432432

433+
val copiedAccessFlags = if (ctx.scala2Setting) EmptyFlags else AccessFlags
434+
433435
// Methods to add to a case class C[..](p1: T1, ..., pN: Tn)(moreParams)
434436
// def _1: T1 = this.p1
435437
// ...
@@ -469,7 +471,7 @@ object desugar {
469471
val copyRestParamss = derivedVparamss.tail.nestedMap(vparam =>
470472
cpy.ValDef(vparam)(rhs = EmptyTree))
471473
DefDef(nme.copy, derivedTparams, copyFirstParams :: copyRestParamss, TypeTree(), creatorExpr)
472-
.withFlags(Synthetic | constr1.mods.flags & AccessFlags) :: Nil
474+
.withFlags(Synthetic | constr1.mods.flags & copiedAccessFlags) :: Nil
473475
}
474476
}
475477

@@ -574,7 +576,7 @@ object desugar {
574576
if (mods is Abstract) Nil
575577
else
576578
DefDef(nme.apply, derivedTparams, derivedVparamss, applyResultTpt, widenedCreatorExpr)
577-
.withFlags(Synthetic | constr1.mods.flags & (DefaultParameterized | AccessFlags)) :: widenDefs
579+
.withFlags(Synthetic | constr1.mods.flags & (DefaultParameterized | copiedAccessFlags)) :: widenDefs
578580
val unapplyMeth = {
579581
val unapplyParam = makeSyntheticParameter(tpt = classTypeRef)
580582
val unapplyRHS = if (arity == 0) Literal(Constant(true)) else Ident(unapplyParam.name)

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
327327
}
328328
scala2Mode
329329
}
330+
331+
/** Is option -language:Scala2 set?
332+
* This test is used when we are too early in the pipeline to consider imports.
333+
*/
334+
def scala2Setting = ctx.settings.language.value.contains(nme.Scala2.toString)
330335
}
331336

332337
object TypeOps {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ object Scanners {
242242

243243
// Scala 2 compatibility
244244

245-
val isScala2Mode: Boolean = ctx.settings.language.value.contains(nme.Scala2.toString)
245+
val isScala2Mode: Boolean = ctx.scala2Setting
246246

247247
/** Cannot use ctx.featureEnabled because accessing the context would force too much */
248248
def testScala2Mode(msg: String, pos: Position = Position(offset)): Boolean = {

0 commit comments

Comments
 (0)