diff options
author | Paul Phillips <paulp@improving.org> | 2012-12-04 09:55:21 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-12-05 09:40:16 -0800 |
commit | e4d1d930693ac75d8eb64c2c3c69f2fc22bec739 (patch) | |
tree | 6baec81832c0b3379bb757e2dd503a8387822762 | |
parent | fd57069a3a49de1757a518b573a0cd8cb98bbbd5 (diff) | |
download | scala-e4d1d930693ac75d8eb64c2c3c69f2fc22bec739.tar.gz scala-e4d1d930693ac75d8eb64c2c3c69f2fc22bec739.tar.bz2 scala-e4d1d930693ac75d8eb64c2c3c69f2fc22bec739.zip |
Warn when generated classfiles differ only in case.
We should most likely prohibit it completely, but warning
is a start.
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala | 9 | ||||
-rw-r--r-- | test/files/neg/case-collision.check | 10 | ||||
-rw-r--r-- | test/files/neg/case-collision.flags | 1 | ||||
-rw-r--r-- | test/files/neg/case-collision.scala | 11 |
4 files changed, 30 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala index 6eb05c4402..61f3721da1 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala @@ -160,7 +160,14 @@ abstract class GenASM extends SubComponent with BytecodeWriters { } // 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.") val bytecodeWriter = initBytecodeWriter(sortedClasses filter isJavaEntryPoint) diff --git a/test/files/neg/case-collision.check b/test/files/neg/case-collision.check new file mode 100644 index 0000000000..4edc6f1205 --- /dev/null +++ b/test/files/neg/case-collision.check @@ -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 diff --git a/test/files/neg/case-collision.flags b/test/files/neg/case-collision.flags new file mode 100644 index 0000000000..85d8eb2ba2 --- /dev/null +++ b/test/files/neg/case-collision.flags @@ -0,0 +1 @@ +-Xfatal-warnings diff --git a/test/files/neg/case-collision.scala b/test/files/neg/case-collision.scala new file mode 100644 index 0000000000..241169a77a --- /dev/null +++ b/test/files/neg/case-collision.scala @@ -0,0 +1,11 @@ +package foo + +class Bippy + +class BIPPY + +object Dingo +object DINGO + +case class Hyrax() +object HyRaX |