Skip to content

Commit

Permalink
Flag class file collision as error (#19332)
Browse files Browse the repository at this point in the history
Fixes #19248
  • Loading branch information
smarter authored Oct 10, 2024
2 parents cd3bd1d + 41e8a12 commit a72b97a
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/PostProcessor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions tests/neg/i19248/Foo.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
trait Foo { // error
class Bar

type T = Foo.this.Bar

inline def f: Int = ???
}
3 changes: 3 additions & 0 deletions tests/neg/i19248/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@main
def Main(args: String*): Unit =
()
4 changes: 4 additions & 0 deletions tests/neg/i19248/Scope.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Scope {
}
object Foo {
}
1 change: 1 addition & 0 deletions tests/neg/i19248/empty.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 3 additions & 0 deletions tests/neg/main-functions-nameclash.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object foo {
@main def foo(x: Int) = () // error: class foo and object foo produce classes that overwrite one another
}
2 changes: 1 addition & 1 deletion tests/pos-with-compiler-cc/backend/jvm/GenBCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 0 additions & 5 deletions tests/warn/main-functions-nameclash.scala

This file was deleted.

0 comments on commit a72b97a

Please sign in to comment.