Skip to content

Commit 278a822

Browse files
committed
Replace -strict with -source 3.1
1 parent 9a828b8 commit 278a822

File tree

11 files changed

+53
-52
lines changed

11 files changed

+53
-52
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import Decorators.{given _}, transform.SymUtils._
99
import NameKinds.{UniqueName, EvidenceParamName, DefaultGetterName}
1010
import typer.{FrontEnd, Namer}
1111
import util.{Property, SourceFile, SourcePosition}
12-
import config.Feature
12+
import config.Feature.{sourceVersion, migrateTo3, enabled}
13+
import config.SourceVersion._
1314
import collection.mutable.ListBuffer
1415
import reporting.messages._
1516
import reporting.trace
@@ -211,7 +212,7 @@ object desugar {
211212
val epbuf = ListBuffer[ValDef]()
212213
def desugarContextBounds(rhs: Tree): Tree = rhs match {
213214
case ContextBounds(tbounds, cxbounds) =>
214-
val iflag = if ctx.settings.strict.value then Given else Implicit
215+
val iflag = if sourceVersion.isAtLeast(`3.1`) then Given else Implicit
215216
epbuf ++= makeImplicitParameters(cxbounds, iflag, forPrimaryConstructor = isPrimaryConstructor)
216217
tbounds
217218
case LambdaTypeTree(tparams, body) =>
@@ -561,7 +562,7 @@ object desugar {
561562
ensureApplied(nu)
562563
}
563564

564-
val copiedAccessFlags = if Feature.migrateTo3 then EmptyFlags else AccessFlags
565+
val copiedAccessFlags = if migrateTo3 then EmptyFlags else AccessFlags
565566

566567
// Methods to add to a case class C[..](p1: T1, ..., pN: Tn)(moreParams)
567568
// def _1: T1 = this.p1
@@ -1660,7 +1661,7 @@ object desugar {
16601661
}
16611662
else {
16621663
assert(ctx.mode.isExpr || ctx.reporter.errorsReported || ctx.mode.is(Mode.Interactive), ctx.mode)
1663-
if (!Feature.enabled(nme.postfixOps)) {
1664+
if (!enabled(nme.postfixOps)) {
16641665
ctx.error(
16651666
s"""postfix operator `${op.name}` needs to be enabled
16661667
|by making the implicit value scala.language.postfixOps visible.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
154154
enum GenCheckMode {
155155
case Ignore // neither filter nor check since filtering was done before
156156
case Check // check that pattern is irrefutable
157-
case FilterNow //filter out non-matching elements since we are not in -strict
157+
case FilterNow //filter out non-matching elements since we are not yet in 3.1
158158
case FilterAlways // filter out non-matching elements since pattern is prefixed by `case`
159159
}
160160

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class ScalaSettings extends Settings.SettingGroup {
4444
val verbose: Setting[Boolean] = BooleanSetting("-verbose", "Output messages about what the compiler is doing.") withAbbreviation "--verbose"
4545
val version: Setting[Boolean] = BooleanSetting("-version", "Print product version and exit.") withAbbreviation "--version"
4646
val pageWidth: Setting[Int] = IntSetting("-pagewidth", "Set page width", 80) withAbbreviation "--page-width"
47-
val strict: Setting[Boolean] = BooleanSetting("-strict", "Use strict type rules, which means some formerly legal code does not typecheck anymore.") withAbbreviation "--strict"
4847
val language: Setting[List[String]] = MultiStringSetting("-language", "feature", "Enable one or more language features.") withAbbreviation "--language"
4948
val rewrite: Setting[Option[Rewrites]] = OptionSetting[Rewrites]("-rewrite", "When used in conjunction with a `...-migration` source version, rewrites sources to migrate to new version.") withAbbreviation "--rewrite"
5049
val silentWarnings: Setting[Boolean] = BooleanSetting("-nowarn", "Silence all warnings.") withAbbreviation "--no-warnings"

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import Contexts._, Types._, Symbols._, Names._, Flags._
66
import Denotations.SingleDenotation
77
import Decorators._
88
import collection.mutable
9+
import config.SourceVersion.`3.1`
10+
import config.Feature.sourceVersion
911

1012
/** Realizability status */
1113
object CheckRealizable {
@@ -197,7 +199,7 @@ class CheckRealizable(implicit ctx: Context) {
197199
realizability(fld.info).mapError(r => new HasProblemField(fld, r))
198200
}
199201
}
200-
if (ctx.settings.strict.value)
202+
if sourceVersion.isAtLeast(`3.1`) then
201203
// check fields only under strict mode for now.
202204
// Reason: An embedded field could well be nullable, which means it
203205
// should not be part of a path and need not be checked; but we cannot recognize

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import scala.annotation.{tailrec, switch}
2828
import rewrites.Rewrites.{patch, overlapsPatch}
2929
import reporting.Message
3030
import reporting.messages._
31+
import config.Feature.sourceVersion
32+
import config.SourceVersion.`3.1`
3133

3234
object Parsers {
3335

@@ -1484,7 +1486,7 @@ object Parsers {
14841486
if in.token == LBRACE || in.token == INDENT then
14851487
t
14861488
else
1487-
if (ctx.settings.strict.value)
1489+
if sourceVersion.isAtLeast(`3.1`) then
14881490
deprecationWarning(DeprecatedWithOperator(), withOffset)
14891491
makeAndType(t, withType())
14901492
else t
@@ -1545,10 +1547,9 @@ object Parsers {
15451547
SingletonTypeTree(literal(negOffset = start, inType = true))
15461548
}
15471549
else if (in.token == USCORE) {
1548-
if (ctx.settings.strict.value) {
1550+
if sourceVersion.isAtLeast(`3.1`) then
15491551
deprecationWarning(em"`_` is deprecated for wildcard arguments of types: use `?` instead")
15501552
patch(source, Span(in.offset, in.offset + 1), "?")
1551-
}
15521553
val start = in.skipToken()
15531554
typeBounds().withSpan(Span(start, in.lastOffset, start))
15541555
}
@@ -2076,7 +2077,7 @@ object Parsers {
20762077
val name = bindingName()
20772078
val t =
20782079
if (in.token == COLON && location == Location.InBlock) {
2079-
if (ctx.settings.strict.value)
2080+
if sourceVersion.isAtLeast(`3.1`)
20802081
// Don't error in non-strict mode, as the alternative syntax "implicit (x: T) => ... "
20812082
// is not supported by Scala2.x
20822083
in.errorOrMigrationWarning(s"This syntax is no longer supported; parameter needs to be enclosed in (...)")
@@ -2396,7 +2397,7 @@ object Parsers {
23962397
atSpan(startOffset(pat), accept(LARROW)) {
23972398
val checkMode =
23982399
if (casePat) GenCheckMode.FilterAlways
2399-
else if (ctx.settings.strict.value) GenCheckMode.Check
2400+
else if sourceVersion.isAtLeast(`3.1`) then GenCheckMode.Check
24002401
else GenCheckMode.FilterNow // filter for now, to keep backwards compat
24012402
GenFrom(pat, subExpr(), checkMode)
24022403
}
@@ -2574,15 +2575,15 @@ object Parsers {
25742575
// compatibility for Scala2 `x @ _*` syntax
25752576
infixPattern() match {
25762577
case pt @ Ident(tpnme.WILDCARD_STAR) =>
2577-
if (ctx.settings.strict.value)
2578+
if sourceVersion.isAtLeast(`3.1`) then
25782579
in.errorOrMigrationWarning("The syntax `x @ _*` is no longer supported; use `x : _*` instead", Span(startOffset(p)))
25792580
atSpan(startOffset(p), offset) { Typed(p, pt) }
25802581
case pt =>
25812582
atSpan(startOffset(p), 0) { Bind(name, pt) }
25822583
}
25832584
case p @ Ident(tpnme.WILDCARD_STAR) =>
25842585
// compatibility for Scala2 `_*` syntax
2585-
if (ctx.settings.strict.value)
2586+
if sourceVersion.isAtLeast(`3.1`) then
25862587
in.errorOrMigrationWarning("The syntax `_*` is no longer supported; use `x : _*` instead", Span(startOffset(p)))
25872588
atSpan(startOffset(p)) { Typed(Ident(nme.WILDCARD), p) }
25882589
case p =>
@@ -2717,7 +2718,7 @@ object Parsers {
27172718
syntaxError(DuplicatePrivateProtectedQualifier())
27182719
inBrackets {
27192720
if in.token == THIS then
2720-
if ctx.settings.strict.value then
2721+
if sourceVersion.isAtLeast(`3.1`) then
27212722
deprecationWarning("The [this] qualifier is deprecated in Scala 3.1; it should be dropped.")
27222723
in.nextToken()
27232724
mods | Local

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ trait Reporting { thisCtx: Context =>
124124
def warning(msg: Message, pos: SourcePosition = NoSourcePosition): Unit =
125125
reportWarning(new Warning(msg, addInlineds(pos)))
126126

127-
def strictWarning(msg: Message, pos: SourcePosition = NoSourcePosition): Unit =
128-
if (thisCtx.settings.strict.value) error(msg, pos)
129-
else warning(msg.append("\n(This would be an error under strict mode)"), pos)
130-
131127
def error(msg: Message, pos: SourcePosition = NoSourcePosition, sticky: Boolean = false): Unit = {
132128
val fullPos = addInlineds(pos)
133129
reporter.report(if (sticky) new StickyError(msg, fullPos) else new Error(msg, fullPos))

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import NameOps._
3232
import SymDenotations.{NoCompleter, NoDenotation}
3333
import Applications.unapplyArgs
3434
import transform.patmat.SpaceEngine.isIrrefutableUnapply
35-
import config.Feature
35+
import config.Feature._
36+
import config.SourceVersion._
3637

3738
import collection.mutable
3839
import reporting.Message
@@ -309,7 +310,8 @@ object Checking {
309310
}
310311
}
311312

312-
/** If `sym` has an operator name, check that it has an @alpha annotation under -strict */
313+
/** If `sym` has an operator name, check that it has an @alpha annotation in 3.1 and later
314+
*/
313315
def checkValidOperator(sym: Symbol)(using Context): Unit =
314316
sym.name.toTermName match {
315317
case name: SimpleName
@@ -318,7 +320,7 @@ object Checking {
318320
&& !name.isConstructorName
319321
&& !sym.getAnnotation(defn.AlphaAnnot).isDefined
320322
&& !sym.is(Synthetic)
321-
&& ctx.settings.strict.value =>
323+
&& sourceVersion.isAtLeast(`3.1`) =>
322324
ctx.deprecationWarning(
323325
i"$sym has an operator name; it should come with an @alpha annotation", sym.sourcePos)
324326
case _ =>
@@ -683,7 +685,7 @@ trait Checking {
683685
def check(pat: Tree, pt: Type): Boolean = (pt <:< pat.tpe) || fail(pat, pt)
684686

685687
def recur(pat: Tree, pt: Type): Boolean =
686-
!ctx.settings.strict.value || // only in -strict mode for now since mitigations work only after this PR
688+
!sourceVersion.isAtLeast(`3.1`) || // only for 3.1 for now since mitigations work only after this PR
687689
pat.tpe.widen.hasAnnotation(defn.UncheckedAnnot) || {
688690
patmatch.println(i"check irrefutable $pat: ${pat.tpe} against $pt")
689691
pat match {
@@ -804,7 +806,7 @@ trait Checking {
804806
!isInfix(meth) &&
805807
!meth.maybeOwner.is(Scala2x) &&
806808
!infixOKSinceFollowedBy(tree.right) &&
807-
ctx.settings.strict.value =>
809+
sourceVersion.isAtLeast(`3.1`) =>
808810
val (kind, alternative) =
809811
if (ctx.mode.is(Mode.Type))
810812
("type", (n: Name) => s"prefix syntax $n[...]")
@@ -831,7 +833,7 @@ trait Checking {
831833
description: => String,
832834
featureUseSite: Symbol,
833835
pos: SourcePosition)(using Context): Unit =
834-
if !Feature.enabled(name) then
836+
if !enabled(name) then
835837
ctx.featureWarning(name.toString, description, featureUseSite, required = false, pos)
836838

837839
/** Check that `tp` is a class type and that any top-level type arguments in this type

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import transform.ValueClasses._
2323
import transform.TypeUtils._
2424
import transform.SymUtils._
2525
import reporting.messages._
26+
import config.Feature.sourceVersion
27+
import config.SourceVersion._
2628

2729
trait NamerContextOps {
2830
thisCtx: Context =>
@@ -1261,7 +1263,7 @@ class Namer { typer: Typer =>
12611263
else if pclazz.isEffectivelySealed && pclazz.associatedFile != cls.associatedFile then
12621264
if pclazz.is(Sealed) then
12631265
completerCtx.error(UnableToExtendSealedClass(pclazz), cls.sourcePos)
1264-
else if completerCtx.settings.strict.value then
1266+
else if sourceVersion.isAtLeast(`3.1`) then
12651267
checkFeature(nme.adhocExtensions,
12661268
i"Unless $pclazz is declared 'open', its extension in a separate file",
12671269
cls.topLevelClass,

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import annotation.tailrec
3434
import Implicits._
3535
import util.Stats.record
3636
import config.Printers.{gadts, typr}
37-
import config.Feature
37+
import config.Feature._
3838
import config.SourceVersion._
3939
import rewrites.Rewrites.patch
4040
import NavigateAST._
@@ -319,7 +319,7 @@ class Typer extends Namer
319319
ctx.errorOrMigrationWarning(
320320
AmbiguousReference(name, Definition, Inheritance, prevCtx)(using outer),
321321
posd.sourcePos)
322-
if Feature.migrateTo3 then
322+
if migrateTo3 then
323323
patch(Span(posd.span.start),
324324
if prevCtx.owner == refctx.owner.enclosingClass then "this."
325325
else s"${prevCtx.owner.name}.this.")
@@ -348,7 +348,7 @@ class Typer extends Namer
348348
checkNoOuterDefs(found.denot, ctx, ctx)
349349
case _ =>
350350
else
351-
if Feature.migrateTo3 && !foundUnderScala2.exists then
351+
if migrateTo3 && !foundUnderScala2.exists then
352352
foundUnderScala2 = checkNewOrShadowed(found, Definition, scala2pkg = true)
353353
if (defDenot.symbol.is(Package))
354354
result = checkNewOrShadowed(previous orElse found, PackageClause)
@@ -1934,7 +1934,7 @@ class Typer extends Namer
19341934
ctx.phase.isTyper &&
19351935
cdef1.symbol.ne(defn.DynamicClass) &&
19361936
cdef1.tpe.derivesFrom(defn.DynamicClass) &&
1937-
!Feature.dynamicsEnabled
1937+
!dynamicsEnabled
19381938
if (reportDynamicInheritance) {
19391939
val isRequired = parents1.exists(_.tpe.isRef(defn.DynamicClass))
19401940
ctx.featureWarning(nme.dynamics.toString, "extension of type scala.Dynamic", cls, isRequired, cdef.sourcePos)
@@ -2103,15 +2103,15 @@ class Typer extends Namer
21032103
case _ =>
21042104
val recovered = typed(qual)(using ctx.fresh.setExploreTyperState())
21052105
ctx.errorOrMigrationWarning(OnlyFunctionsCanBeFollowedByUnderscore(recovered.tpe.widen), tree.sourcePos)
2106-
if (Feature.migrateTo3) {
2106+
if (migrateTo3) {
21072107
// Under -rewrite, patch `x _` to `(() => x)`
21082108
patch(Span(tree.span.start), "(() => ")
21092109
patch(Span(qual.span.end, tree.span.end), ")")
21102110
return typed(untpd.Function(Nil, qual), pt)
21112111
}
21122112
}
21132113
nestedCtx.typerState.commit()
2114-
if (ctx.settings.strict.value) {
2114+
if sourceVersion.isAtLeast(`3.1`) then
21152115
lazy val (prefix, suffix) = res match {
21162116
case Block(mdef @ DefDef(_, _, vparams :: Nil, _, _) :: Nil, _: Closure) =>
21172117
val arity = vparams.length
@@ -2123,12 +2123,11 @@ class Typer extends Namer
21232123
if ((prefix ++ suffix).isEmpty) "simply leave out the trailing ` _`"
21242124
else s"use `$prefix<function>$suffix` instead"
21252125
ctx.errorOrMigrationWarning(i"""The syntax `<function> _` is no longer supported;
2126-
|you can $remedy""", tree.sourcePos)
2127-
if (Feature.migrateTo3) {
2126+
|you can $remedy""", tree.sourcePos, `3.1`)
2127+
if sourceVersion.isMigrating then
21282128
patch(Span(tree.span.start), prefix)
21292129
patch(Span(qual.span.end, tree.span.end), suffix)
2130-
}
2131-
}
2130+
end if
21322131
res
21332132
}
21342133

@@ -2756,17 +2755,16 @@ class Typer extends Namer
27562755
case wtp: MethodOrPoly =>
27572756
def methodStr = methPart(tree).symbol.showLocated
27582757
if (matchingApply(wtp, pt))
2759-
if (pt.args.lengthCompare(1) > 0 && isUnary(wtp) && Feature.autoTuplingEnabled)
2758+
if (pt.args.lengthCompare(1) > 0 && isUnary(wtp) && autoTuplingEnabled)
27602759
adapt(tree, pt.tupled, locked)
27612760
else
27622761
tree
27632762
else if (wtp.isContextualMethod)
27642763
def isContextBoundParams = wtp.stripPoly match
27652764
case MethodType(EvidenceParamName(_) :: _) => true
27662765
case _ => false
2767-
if ctx.settings.migration.value && ctx.settings.strict.value
2768-
&& isContextBoundParams
2769-
then // Under 3.1 and -migration, don't infer implicit arguments yet for parameters
2766+
if sourceVersion == `3.1-migration` && isContextBoundParams
2767+
then // Under 3.1-migration, don't infer implicit arguments yet for parameters
27702768
// coming from context bounds. Issue a warning instead and offer a patch.
27712769
ctx.migrationWarning(
27722770
em"""Context bounds will map to context parameters.
@@ -2928,7 +2926,7 @@ class Typer extends Namer
29282926
def isAutoApplied(sym: Symbol): Boolean =
29292927
sym.isConstructor
29302928
|| sym.matchNullaryLoosely
2931-
|| Feature.warnOnMigration(MissingEmptyArgumentList(sym), tree.sourcePos)
2929+
|| warnOnMigration(MissingEmptyArgumentList(sym), tree.sourcePos)
29322930
&& { patch(tree.span.endPos, "()"); true }
29332931

29342932
// Reasons NOT to eta expand:
@@ -3266,7 +3264,7 @@ class Typer extends Namer
32663264
case ref: TermRef =>
32673265
pt match {
32683266
case pt: FunProto
3269-
if pt.args.lengthCompare(1) > 0 && isUnary(ref) && Feature.autoTuplingEnabled =>
3267+
if pt.args.lengthCompare(1) > 0 && isUnary(ref) && autoTuplingEnabled =>
32703268
adapt(tree, pt.tupled, locked)
32713269
case _ =>
32723270
adaptOverloaded(ref)

0 commit comments

Comments
 (0)