diff --git a/community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala b/community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala index 11462dc88146..1c2c8aba7321 100644 --- a/community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala +++ b/community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala @@ -216,7 +216,7 @@ object projects lazy val stdLib213 = SbtCommunityProject( project = "stdLib213", - sbtTestCommand = "library/compile", + sbtTestCommand = """;set scalacOptions in Global += "-Yerased-terms" ;library/compile""", sbtUpdateCommand = "library/update", extraSbtArgs = List("-Dscala.build.compileWithDotty=true") ) diff --git a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala index 54e1765a7df5..0d3024a8ccee 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Scanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Scanners.scala @@ -202,7 +202,8 @@ object Scanners { private val commentBuf = new mutable.StringBuilder private def handleMigration(keyword: Token): Token = - if (!isScala2CompatMode) keyword + if (keyword == ERASED && !ctx.settings.YerasedTerms.value) IDENTIFIER + else if (!isScala2CompatMode) keyword else if (scala3keywords.contains(keyword)) treatAsIdent() else keyword diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 7e71230ebbb1..7df77bcee979 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -457,8 +457,7 @@ object Checking { sym.setFlag(Private) // break the overriding relationship by making sym Private } if (sym.is(Erased)) - if ctx.settings.YerasedTerms.value || sym == defn.Compiletime_erasedValue then checkApplicable(Erased, !sym.isOneOf(MutableOrLazy)) - else fail("cannot use `erased` without " + ctx.settings.YerasedTerms.name) + checkApplicable(Erased, !sym.isOneOf(MutableOrLazy)) } /** Check the type signature of the symbol `M` defined by `tree` does not refer diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index feacb283ef40..8e5cf657a624 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -224,6 +224,7 @@ class CompilationTests extends ParallelTesting { val lib = compileList("src", librarySources, defaultOptions.and("-Ycheck-reentrant", + "-Yerased-terms", // support declaration of scala.compiletime.erasedValue // "-strict", // TODO: re-enable once we allow : @unchecked in pattern definitions. Right now, lots of narrowing pattern definitions fail. "-priorityclasspath", defaultOutputDir))(libGroup) diff --git a/project/Build.scala b/project/Build.scala index 8f740af54537..daea2b962781 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -737,6 +737,8 @@ object Build { lazy val `dotty-library` = project.in(file("library")).asDottyLibrary(NonBootstrapped) lazy val `dotty-library-bootstrapped`: Project = project.in(file("library")).asDottyLibrary(Bootstrapped) + // TODO: move -Yerased-terms to dottyLibrarySettings on reference compiler update + .settings(scalacOptions in Compile += "-Yerased-terms") // support declaration of scala.compiletime.erasedValue def dottyLibrary(implicit mode: Mode): Project = mode match { case NonBootstrapped => `dotty-library` @@ -758,6 +760,7 @@ object Build { settings( unmanagedSourceDirectories in Compile := (unmanagedSourceDirectories in (`dotty-library-bootstrapped`, Compile)).value, + scalacOptions += "-Yerased-terms", // support declaration of scala.compiletime.erasedValue ) lazy val tastyCoreSettings = Seq( @@ -990,7 +993,7 @@ object Build { val dir = fetchScalaJSSource.value / "test-suite" ( (dir / "shared/src/test/scala/org/scalajs/testsuite/compiler" ** (("*.scala":FileFilter) -- "RegressionTest.scala" -- "ReflectiveCallTest.scala")).get - ++ (dir / "shared/src/test/scala/org/scalajs/testsuite/javalib/lang" ** (("*.scala": FileFilter) -- "StringTest.scala")).get + ++ (dir / "shared/src/test/scala/org/scalajs/testsuite/javalib/lang" ** "*.scala").get ++ (dir / "shared/src/test/scala/org/scalajs/testsuite/javalib/io" ** (("*.scala": FileFilter) -- "ReadersTest.scala")).get ++ (dir / "shared/src/test/scala/org/scalajs/testsuite/javalib/math" ** "*.scala").get ++ (dir / "shared/src/test/scala/org/scalajs/testsuite/javalib/net" ** "*.scala").get diff --git a/tests/pos/i7944.scala b/tests/pos/i7944.scala new file mode 100644 index 000000000000..d18d1ee5fddc --- /dev/null +++ b/tests/pos/i7944.scala @@ -0,0 +1,8 @@ +package hello + +object HelloWorld { + def main(args: Array[String]): Unit = + println(erased(5)) + + def erased(x: Int): Any = x +}