Skip to content

Commit 4a257df

Browse files
Merge pull request #4120 from dotty-staging/fix-FromTastTests-with-name-issues
Fix tests on case-insensitive filesystems
2 parents ca6e2cc + 5a90545 commit 4a257df

File tree

7 files changed

+45
-21
lines changed

7 files changed

+45
-21
lines changed

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

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
159159
*/
160160
class Worker1(needsOutFolder: Boolean) {
161161

162-
val caseInsensitively = scala.collection.mutable.Map.empty[String, Symbol]
162+
val caseInsensitively = scala.collection.mutable.HashMap.empty[String, Symbol]
163163

164164
def run(): Unit = {
165165
while (true) {
@@ -190,19 +190,25 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
190190
val claszSymbol = cd.symbol
191191

192192
// GenASM checks this before classfiles are emitted, https://github.com/scala/scala/commit/e4d1d930693ac75d8eb64c2c3c69f2fc22bec739
193-
val lowercaseJavaClassName = claszSymbol.name.toString.toLowerCase
194-
caseInsensitively.get(lowercaseJavaClassName) match {
195-
case None =>
196-
caseInsensitively.put(lowercaseJavaClassName, claszSymbol)
197-
case Some(dupClassSym) =>
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)
193+
def checkName(claszSymbol: Symbol): Unit = {
194+
val lowercaseJavaClassName = claszSymbol.effectiveName.toString.toLowerCase
195+
caseInsensitively.get(lowercaseJavaClassName) match {
196+
case None =>
197+
caseInsensitively.put(lowercaseJavaClassName, claszSymbol)
198+
case Some(dupClassSym) =>
199+
if (claszSymbol.effectiveName.toString != dupClassSym.effectiveName.toString) {
200+
// Order is not deterministic so we enforce lexicographic order between the duplicates for error-reporting
201+
val (cl1, cl2) =
202+
if (claszSymbol.effectiveName.toString < dupClassSym.effectiveName.toString) (claszSymbol, dupClassSym)
203+
else (dupClassSym, claszSymbol)
204+
ctx.warning(s"Class ${cl1.effectiveName} differs only in case from ${cl2.effectiveName}. " +
205+
"Such classes will overwrite one another on case-insensitive filesystems.", cl1.pos)
206+
}
207+
}
205208
}
209+
checkName(claszSymbol)
210+
if (int.symHelper(claszSymbol).isModuleClass)
211+
checkName(claszSymbol.companionModule)
206212

207213
// -------------- mirror class, if needed --------------
208214
val mirrorC =

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class CompilationTests extends ParallelTesting {
5858
compileFile("tests/pos-special/i3323.scala", defaultOptions.and("-Xfatal-warnings")) +
5959
compileFile("tests/pos-special/i3323b.scala", defaultOptions.and("-Xfatal-warnings")) +
6060
compileFile("tests/pos-special/i3589-b.scala", defaultOptions.and("-Xfatal-warnings")) +
61+
compileFile("tests/pos-special/i4166.scala", defaultOptions.and("-Xfatal-warnings")) +
6162
compileFile("tests/pos-special/completeFromSource/Test.scala", defaultOptions.and("-sourcepath", "tests/pos-special")) +
6263
compileFile("tests/pos-special/completeFromSource/Test2.scala", defaultOptions.and("-sourcepath", "tests/pos-special")) +
6364
compileFile("tests/pos-special/completeFromSource/Test3.scala", defaultOptions.and("-sourcepath", "tests/pos-special", "-scansource")) +
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package Foos
2+
3+
class Bar // error
4+
object bar
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package Foos
2+
3+
object Outer {
4+
class X // error
5+
object x
6+
}

tests/pos-special/i4166.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package foo {
2+
class Hello
3+
}
4+
5+
package bar {
6+
class Hello
7+
}

tests/pos/test4a.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ class O[X]() {
77
val j:I[X] = null;
88
}
99

10-
object o extends O[C]() {
10+
object p extends O[C]() {
1111
def c: C = c;
1212
def main = {
13-
o.j.foo(c);
13+
p.j.foo(c);
1414
}
1515
}
1616

tests/pos/test4refine.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object test {
1010

1111
import test._;
1212

13-
trait S extends o.I {
13+
trait S extends p.I {
1414
type Y = D;
1515
def bar: E = foo(c,d);
1616
}
@@ -25,15 +25,15 @@ abstract class O() {
2525
val j:I { type Y = X } = null;
2626
}
2727

28-
object o extends O() {
28+
object p extends O() {
2929
type X = C;
3030

3131
def main = {
3232
val s: S = null;
3333
import s._;
3434
foo(c,d);
35-
o.i.foo(c,e);
36-
o.j.foo(c,c);
35+
p.i.foo(c,e);
36+
p.j.foo(c,c);
3737
bar
3838
}
3939
}
@@ -42,8 +42,8 @@ class Main() {
4242
val s: S = null;
4343
import s._;
4444
foo(c,d);
45-
o.i.foo(c,e);
46-
o.j.foo(c,c);
45+
p.i.foo(c,e);
46+
p.j.foo(c,c);
4747
bar;
4848
}
4949

0 commit comments

Comments
 (0)