Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit 01c673e

Browse files
committed
SI-5760: Improve error message for package$Klass conflict with Klass
Added a clarification to DoubleDefError for when the previous symbol was in the package object but current symbol is not. This was actually supposed to be an opportunity to hack partest to run the two-step failing compilation, but somebody beat me to it and my rebase failed. The next hacking opportunity might be to add .pt script files! The possibilities are endless.
1 parent 1f5584f commit 01c673e

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

src/compiler/scala/tools/nsc/typechecker/ContextErrors.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,12 @@ trait ContextErrors {
874874
val s1 = if (prevSym.isModule) "case class companion " else ""
875875
val s2 = if (prevSym.isSynthetic) "(compiler-generated) " + s1 else ""
876876
val s3 = if (prevSym.isCase) "case class " + prevSym.name else "" + prevSym
877+
val where = if (currentSym.owner.isPackageClass != prevSym.owner.isPackageClass) {
878+
val inOrOut = if (prevSym.owner.isPackageClass) "outside of" else "in"
879+
" %s package object %s".format(inOrOut, ""+prevSym.effectiveOwner.name)
880+
} else ""
877881

878-
issueSymbolTypeError(currentSym, prevSym.name + " is already defined as " + s2 + s3)
882+
issueSymbolTypeError(currentSym, prevSym.name + " is already defined as " + s2 + s3 + where)
879883
}
880884

881885
def MaxParametersCaseClassError(tree: Tree) =
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
stalepkg_2.scala:6: error: Foo is already defined as class Foo in package object stalepkg
2+
class Foo
3+
^
4+
one error found
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
package object stalepkg {
3+
class Foo
4+
}
5+
6+
package stalepkg {
7+
object Test {
8+
def main(args: Array[String]) {
9+
}
10+
}
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
package object stalepkg {
3+
}
4+
5+
package stalepkg {
6+
class Foo
7+
object Test {
8+
def main(args: Array[String]) {
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)