Skip to content

Commit

Permalink
Warn when generated classfiles differ only in case.
Browse files Browse the repository at this point in the history
We should most likely prohibit it completely, but warning
is a start.
  • Loading branch information
paulp committed Dec 5, 2012
1 parent fd57069 commit e4d1d93
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -160,7 +160,14 @@ abstract class GenASM extends SubComponent with BytecodeWriters {
} }


// For predictably ordered error messages. // For predictably ordered error messages.
var sortedClasses = classes.values.toList sortBy ("" + _.symbol.fullName) var sortedClasses = classes.values.toList sortBy (_.symbol.fullName)

// Warn when classes will overwrite one another on case-insensitive systems.
for ((_, v1 :: v2 :: _) <- sortedClasses groupBy (_.symbol.javaClassName.toString.toLowerCase)) {
v1.cunit.warning(v1.symbol.pos,
s"Class ${v1.symbol.javaClassName} differs only in case from ${v2.symbol.javaClassName}. " +
"Such classes will overwrite one another on case-insensitive filesystems.")
}


debuglog("Created new bytecode generator for " + classes.size + " classes.") debuglog("Created new bytecode generator for " + classes.size + " classes.")
val bytecodeWriter = initBytecodeWriter(sortedClasses filter isJavaEntryPoint) val bytecodeWriter = initBytecodeWriter(sortedClasses filter isJavaEntryPoint)
Expand Down
10 changes: 10 additions & 0 deletions test/files/neg/case-collision.check
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,10 @@
case-collision.scala:5: error: Class foo.BIPPY differs only in case from foo.Bippy. Such classes will overwrite one another on case-insensitive filesystems.
class BIPPY
^
case-collision.scala:11: error: Class foo.HyRaX$ differs only in case from foo.Hyrax$. Such classes will overwrite one another on case-insensitive filesystems.
object HyRaX
^
case-collision.scala:8: error: Class foo.DINGO$ differs only in case from foo.Dingo$. Such classes will overwrite one another on case-insensitive filesystems.
object DINGO
^
three errors found
1 change: 1 addition & 0 deletions test/files/neg/case-collision.flags
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
-Xfatal-warnings
11 changes: 11 additions & 0 deletions test/files/neg/case-collision.scala
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,11 @@
package foo

class Bippy

class BIPPY

object Dingo
object DINGO

case class Hyrax()
object HyRaX

0 comments on commit e4d1d93

Please sign in to comment.