Skip to content

Commit e78a0be

Browse files
authored
Merge pull request #3897 from biboudis/fix-#2681
Fix #2681: re-enable check for potentially overridden classfiles
2 parents bdf5d80 + 1f4d527 commit e78a0be

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import Contexts._
2424
import Types._
2525
import Symbols._
2626
import Denotations._
27+
import Decorators._
28+
2729
import Phases._
2830
import java.lang.AssertionError
2931
import java.io.{DataOutputStream, File => JFile}
@@ -188,18 +190,19 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
188190
val claszSymbol = cd.symbol
189191

190192
// GenASM checks this before classfiles are emitted, https://github.com/scala/scala/commit/e4d1d930693ac75d8eb64c2c3c69f2fc22bec739
191-
// todo: add back those checks
192-
/*val lowercaseJavaClassName = claszSymbol.javaClassName.toLowerCase
193+
val lowercaseJavaClassName = claszSymbol.name.toString.toLowerCase
193194
caseInsensitively.get(lowercaseJavaClassName) match {
194195
case None =>
195196
caseInsensitively.put(lowercaseJavaClassName, claszSymbol)
196197
case Some(dupClassSym) =>
197-
reporter.warning(
198-
claszSymbol.pos,
199-
s"Class ${claszSymbol.javaClassName} differs only in case from ${dupClassSym.javaClassName}. " +
200-
"Such classes will overwrite one another on case-insensitive filesystems."
201-
)
202-
}*/
198+
// Order is not deterministic so we enforce lexicographic order between the duplicates for error-reporting
199+
if (claszSymbol.name.toString < dupClassSym.name.toString)
200+
ctx.warning(s"Class ${claszSymbol.name} differs only in case from ${dupClassSym.name}. " +
201+
"Such classes will overwrite one another on case-insensitive filesystems.", claszSymbol.pos)
202+
else
203+
ctx.warning(s"Class ${dupClassSym.name} differs only in case from ${claszSymbol.name}. " +
204+
"Such classes will overwrite one another on case-insensitive filesystems.", dupClassSym.pos)
205+
}
203206

204207
// -------------- mirror class, if needed --------------
205208
val mirrorC =

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ class CompilationTests extends ParallelTesting {
194194
compileFile("../tests/neg-custom-args/i3882.scala", allowDeepSubtypes) +
195195
compileFile("../tests/neg-custom-args/phantom-overload.scala", allowDoubleBindings) +
196196
compileFile("../tests/neg-custom-args/phantom-overload-2.scala", allowDoubleBindings) +
197-
compileFile("../tests/neg-custom-args/structural.scala", defaultOptions.and("-Xfatal-warnings"))
197+
compileFile("../tests/neg-custom-args/structural.scala", defaultOptions.and("-Xfatal-warnings")) +
198+
compileFile("../tests/neg-custom-args/i2673.scala", defaultOptions.and("-Xfatal-warnings"))
198199
}.checkExpectedErrors()
199200

200201
// Run tests -----------------------------------------------------------------

tests/neg-custom-args/i2673.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package Foos
2+
3+
class Foo // error
4+
class foo

0 commit comments

Comments
 (0)