Skip to content

Commit 79ba06c

Browse files
authored
Merge pull request #11385 from dotty-staging/safe-object-init3
Enable -Ycheck-init on community projects and CI
2 parents 0b697d5 + db19f60 commit 79ba06c

28 files changed

+600
-423
lines changed

community-build/src/scala/dotty/communitybuild/projects.scala

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,17 @@ final case class SbtCommunityProject(
9090
extraSbtArgs: List[String] = Nil,
9191
dependencies: List[CommunityProject] = Nil,
9292
sbtPublishCommand: String = null,
93-
sbtDocCommand: String = null
93+
sbtDocCommand: String = null,
94+
scalacOptions: List[String] = List("-Ycheck-init")
9495
) extends CommunityProject:
9596
override val binaryName: String = "sbt"
9697

98+
private def scalacOptionsString: String =
99+
scalacOptions.map("\"" + _ + "\"").mkString("List(", ",", ")")
100+
97101
private val baseCommand =
98102
"clean; set logLevel in Global := Level.Error; set updateOptions in Global ~= (_.withLatestSnapshots(false)); "
103+
++ (if scalacOptions.isEmpty then "" else s"""set scalacOptions in Global ++= $scalacOptionsString;""")
99104
++ s"++$compilerVersion!; "
100105

101106
override val testCommand =
@@ -307,7 +312,8 @@ object projects:
307312
lazy val shapeless = SbtCommunityProject(
308313
project = "shapeless",
309314
sbtTestCommand = "test",
310-
sbtDocCommand = forceDoc("typeable", "deriving", "data")
315+
sbtDocCommand = forceDoc("typeable", "deriving", "data"),
316+
scalacOptions = Nil // disable -Ycheck-init, due to -Xfatal-warnings
311317
)
312318

313319
lazy val xmlInterpolator = SbtCommunityProject(
@@ -466,7 +472,8 @@ object projects:
466472
project = "discipline-specs2",
467473
sbtTestCommand = "test",
468474
sbtPublishCommand = "coreJVM/publishLocal;coreJS/publishLocal",
469-
dependencies = List(discipline)
475+
dependencies = List(discipline),
476+
scalacOptions = Nil // disable -Ycheck-init
470477
)
471478

472479
lazy val simulacrumScalafixAnnotations = SbtCommunityProject(
@@ -479,7 +486,8 @@ object projects:
479486
project = "cats",
480487
sbtTestCommand = "set scalaJSStage in Global := FastOptStage;buildJVM;validateAllJS",
481488
sbtPublishCommand = "catsJVM/publishLocal;catsJS/publishLocal",
482-
dependencies = List(discipline, disciplineMunit, scalacheck, simulacrumScalafixAnnotations)
489+
dependencies = List(discipline, disciplineMunit, scalacheck, simulacrumScalafixAnnotations),
490+
scalacOptions = Nil // disable -Ycheck-init, due to -Xfatal-warning
483491
)
484492

485493
lazy val catsMtl = SbtCommunityProject(

compiler/src/dotty/tools/dotc/transform/init/Checker.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import ast.tpd
99
import dotty.tools.dotc.core._
1010
import Contexts._
1111
import Types._
12+
import Symbols._
1213

1314
import dotty.tools.dotc.transform._
1415
import MegaPhase._
@@ -45,7 +46,7 @@ class Checker extends MiniPhase {
4546
}
4647

4748
// A concrete class may not be instantiated if the self type is not satisfied
48-
if (instantiable) {
49+
if (instantiable && cls.enclosingPackageClass != defn.StdLibPatchesPackage.moduleClass) {
4950
implicit val state: Checking.State = Checking.State(
5051
visited = Set.empty,
5152
path = Vector.empty,

0 commit comments

Comments
 (0)