Skip to content

Commit b4d6f4d

Browse files
Merge pull request #7947 from dotty-staging/fix-#7944
Fix #7944: Only treat erased as a keyword under -Yerased-terms
2 parents a2a3dff + 463d04f commit b4d6f4d

File tree

6 files changed

+17
-5
lines changed

6 files changed

+17
-5
lines changed

community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ object projects
216216

217217
lazy val stdLib213 = SbtCommunityProject(
218218
project = "stdLib213",
219-
sbtTestCommand = "library/compile",
219+
sbtTestCommand = """;set scalacOptions in Global += "-Yerased-terms" ;library/compile""",
220220
sbtUpdateCommand = "library/update",
221221
extraSbtArgs = List("-Dscala.build.compileWithDotty=true")
222222
)

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ object Scanners {
202202
private val commentBuf = new mutable.StringBuilder
203203

204204
private def handleMigration(keyword: Token): Token =
205-
if (!isScala2CompatMode) keyword
205+
if (keyword == ERASED && !ctx.settings.YerasedTerms.value) IDENTIFIER
206+
else if (!isScala2CompatMode) keyword
206207
else if (scala3keywords.contains(keyword)) treatAsIdent()
207208
else keyword
208209

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,7 @@ object Checking {
457457
sym.setFlag(Private) // break the overriding relationship by making sym Private
458458
}
459459
if (sym.is(Erased))
460-
if ctx.settings.YerasedTerms.value || sym == defn.Compiletime_erasedValue then checkApplicable(Erased, !sym.isOneOf(MutableOrLazy))
461-
else fail("cannot use `erased` without " + ctx.settings.YerasedTerms.name)
460+
checkApplicable(Erased, !sym.isOneOf(MutableOrLazy))
462461
}
463462

464463
/** Check the type signature of the symbol `M` defined by `tree` does not refer

compiler/test/dotty/tools/dotc/CompilationTests.scala

+1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ class CompilationTests extends ParallelTesting {
224224
val lib =
225225
compileList("src", librarySources,
226226
defaultOptions.and("-Ycheck-reentrant",
227+
"-Yerased-terms", // support declaration of scala.compiletime.erasedValue
227228
// "-strict", // TODO: re-enable once we allow : @unchecked in pattern definitions. Right now, lots of narrowing pattern definitions fail.
228229
"-priorityclasspath", defaultOutputDir))(libGroup)
229230

project/Build.scala

+4-1
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,8 @@ object Build {
737737

738738
lazy val `dotty-library` = project.in(file("library")).asDottyLibrary(NonBootstrapped)
739739
lazy val `dotty-library-bootstrapped`: Project = project.in(file("library")).asDottyLibrary(Bootstrapped)
740+
// TODO: move -Yerased-terms to dottyLibrarySettings on reference compiler update
741+
.settings(scalacOptions in Compile += "-Yerased-terms") // support declaration of scala.compiletime.erasedValue
740742

741743
def dottyLibrary(implicit mode: Mode): Project = mode match {
742744
case NonBootstrapped => `dotty-library`
@@ -758,6 +760,7 @@ object Build {
758760
settings(
759761
unmanagedSourceDirectories in Compile :=
760762
(unmanagedSourceDirectories in (`dotty-library-bootstrapped`, Compile)).value,
763+
scalacOptions += "-Yerased-terms", // support declaration of scala.compiletime.erasedValue
761764
)
762765

763766
lazy val tastyCoreSettings = Seq(
@@ -990,7 +993,7 @@ object Build {
990993
val dir = fetchScalaJSSource.value / "test-suite"
991994
(
992995
(dir / "shared/src/test/scala/org/scalajs/testsuite/compiler" ** (("*.scala":FileFilter) -- "RegressionTest.scala" -- "ReflectiveCallTest.scala")).get
993-
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/javalib/lang" ** (("*.scala": FileFilter) -- "StringTest.scala")).get
996+
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/javalib/lang" ** "*.scala").get
994997
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/javalib/io" ** (("*.scala": FileFilter) -- "ReadersTest.scala")).get
995998
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/javalib/math" ** "*.scala").get
996999
++ (dir / "shared/src/test/scala/org/scalajs/testsuite/javalib/net" ** "*.scala").get

tests/pos/i7944.scala

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package hello
2+
3+
object HelloWorld {
4+
def main(args: Array[String]): Unit =
5+
println(erased(5))
6+
7+
def erased(x: Int): Any = x
8+
}

0 commit comments

Comments
 (0)