From 632278e9c78a3bd4067d8caf649d8d07fd96f2b9 Mon Sep 17 00:00:00 2001 From: friendseeker <66892505+Friendseeker@users.noreply.github.com> Date: Mon, 25 Dec 2023 15:27:28 -0800 Subject: [PATCH 1/3] Flag class file collision as error --- compiler/src/dotty/tools/backend/jvm/PostProcessor.scala | 2 +- tests/pos-with-compiler-cc/backend/jvm/GenBCode.scala | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/backend/jvm/PostProcessor.scala b/compiler/src/dotty/tools/backend/jvm/PostProcessor.scala index 06c3c7f1cb4f..9f172806a3b5 100644 --- a/compiler/src/dotty/tools/backend/jvm/PostProcessor.scala +++ b/compiler/src/dotty/tools/backend/jvm/PostProcessor.scala @@ -73,7 +73,7 @@ class PostProcessor(val frontendAccess: PostProcessorFrontendAccess, val bTypes: else s" (defined in ${pos2.source.file.name})" def nicify(name: String): String = name.replace('/', '.').nn if name1 == name2 then - backendReporting.warning( + backendReporting.error( em"${nicify(name1)} and ${nicify(name2)} produce classes that overwrite one another", pos1) else backendReporting.warning( diff --git a/tests/pos-with-compiler-cc/backend/jvm/GenBCode.scala b/tests/pos-with-compiler-cc/backend/jvm/GenBCode.scala index 1af7e5dd705a..3bc9fb5592ee 100644 --- a/tests/pos-with-compiler-cc/backend/jvm/GenBCode.scala +++ b/tests/pos-with-compiler-cc/backend/jvm/GenBCode.scala @@ -214,7 +214,7 @@ class GenBCodePipeline(val int: DottyBackendInterface, val primitives: DottyPrim val same = classSymbol.effectiveName.toString == dupClassSym.effectiveName.toString atPhase(typerPhase) { if (same) - report.warning( // FIXME: This should really be an error, but then FromTasty tests fail + report.error( em"$cl1 and ${cl2.showLocated} produce classes that overwrite one another", cl1.sourcePos) else report.warning( From ac05bd5950ac9af26533930ef1d88724aca95f99 Mon Sep 17 00:00:00 2001 From: Friendseeker <66892505+Friendseeker@users.noreply.github.com> Date: Wed, 9 Oct 2024 11:57:15 -0700 Subject: [PATCH 2/3] Add test case neg/i19248 --- tests/neg/i19248/Foo.scala | 7 +++++++ tests/neg/i19248/Main.scala | 3 +++ tests/neg/i19248/Scope.scala | 4 ++++ tests/neg/i19248/empty.scala | 1 + 4 files changed, 15 insertions(+) create mode 100644 tests/neg/i19248/Foo.scala create mode 100644 tests/neg/i19248/Main.scala create mode 100644 tests/neg/i19248/Scope.scala create mode 100644 tests/neg/i19248/empty.scala diff --git a/tests/neg/i19248/Foo.scala b/tests/neg/i19248/Foo.scala new file mode 100644 index 000000000000..f24651234eb9 --- /dev/null +++ b/tests/neg/i19248/Foo.scala @@ -0,0 +1,7 @@ +trait Foo { // error + class Bar + + type T = Foo.this.Bar + + inline def f: Int = ??? +} diff --git a/tests/neg/i19248/Main.scala b/tests/neg/i19248/Main.scala new file mode 100644 index 000000000000..bf4e3a48b279 --- /dev/null +++ b/tests/neg/i19248/Main.scala @@ -0,0 +1,3 @@ +@main +def Main(args: String*): Unit = + () diff --git a/tests/neg/i19248/Scope.scala b/tests/neg/i19248/Scope.scala new file mode 100644 index 000000000000..a3135d93084f --- /dev/null +++ b/tests/neg/i19248/Scope.scala @@ -0,0 +1,4 @@ +object Scope { +} +object Foo { +} diff --git a/tests/neg/i19248/empty.scala b/tests/neg/i19248/empty.scala new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/tests/neg/i19248/empty.scala @@ -0,0 +1 @@ + From 41e8a126443e85bebfc8e9de84fb7949e845f981 Mon Sep 17 00:00:00 2001 From: Friendseeker <66892505+Friendseeker@users.noreply.github.com> Date: Wed, 9 Oct 2024 15:40:43 -0700 Subject: [PATCH 3/3] Reclassify main-functions-nameclash test --- tests/neg/main-functions-nameclash.scala | 3 +++ tests/warn/main-functions-nameclash.scala | 5 ----- 2 files changed, 3 insertions(+), 5 deletions(-) create mode 100644 tests/neg/main-functions-nameclash.scala delete mode 100644 tests/warn/main-functions-nameclash.scala diff --git a/tests/neg/main-functions-nameclash.scala b/tests/neg/main-functions-nameclash.scala new file mode 100644 index 000000000000..23a530e28271 --- /dev/null +++ b/tests/neg/main-functions-nameclash.scala @@ -0,0 +1,3 @@ +object foo { + @main def foo(x: Int) = () // error: class foo and object foo produce classes that overwrite one another +} diff --git a/tests/warn/main-functions-nameclash.scala b/tests/warn/main-functions-nameclash.scala deleted file mode 100644 index bc0fe64379d4..000000000000 --- a/tests/warn/main-functions-nameclash.scala +++ /dev/null @@ -1,5 +0,0 @@ - - -object foo { - @main def foo(x: Int) = () // warn: class foo and object foo produce classes that overwrite one another -}