File tree Expand file tree Collapse file tree 4 files changed +38
-1
lines changed
test/dotty/tools/dotc/reporting Expand file tree Collapse file tree 4 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,7 @@ public enum ErrorMessageID {
125125 UnableToEmitSwitchID ,
126126 MissingCompanionForStaticID ,
127127 PolymorphicMethodMissingTypeInParentID ,
128+ JavaSymbolIsNotAValueID ,
128129 ;
129130
130131 public int errorNumber () {
Original file line number Diff line number Diff line change @@ -2069,4 +2069,26 @@ object messages {
20692069 | $rsym does not override any method in $parentSym. Structural refinement does not allow for
20702070 |polymorphic methods. """
20712071 }
2072+
2073+ case class JavaSymbolIsNotAValue (symbol : Symbol )(implicit ctx : Context ) extends Message (JavaSymbolIsNotAValueID ) {
2074+ val msg = hl " $symbol is not a value "
2075+ val kind = " Type Mismatch"
2076+ val explanation = {
2077+ val javaCodeExample = """ class A {public static int a() {return 1;}}"""
2078+
2079+ val scalaCodeExample =
2080+ """ val objectA = A // This does not compile
2081+ |val aResult = A.a() // This does compile""" .stripMargin
2082+
2083+ hl """ Java statics and packages cannot be used as a value.
2084+ |For Java statics consider the following Java example:
2085+ |
2086+ | $javaCodeExample
2087+ |
2088+ |When used from Scala:
2089+ |
2090+ | $scalaCodeExample"""
2091+ }
2092+ }
2093+
20722094}
Original file line number Diff line number Diff line change @@ -523,7 +523,7 @@ trait Checking {
523523 val sym = tree.tpe.termSymbol
524524 // The check is avoided inside Java compilation units because it always fails
525525 // on the singleton type Module.type.
526- if ((sym is Package ) || ((sym is JavaModule ) && ! ctx.compilationUnit.isJava)) ctx.error(em " $ sym is not a value " , tree.pos)
526+ if ((sym is Package ) || ((sym is JavaModule ) && ! ctx.compilationUnit.isJava)) ctx.error(JavaSymbolIsNotAValue ( sym) , tree.pos)
527527 }
528528 tree
529529 }
Original file line number Diff line number Diff line change @@ -1279,4 +1279,18 @@ class ErrorMessagesTests extends ErrorMessagesTest {
12791279 assertEquals(" method get" , rsym.show)
12801280 assertEquals(" class Object" , parentSym.show)
12811281 }
1282+
1283+ @ Test def javaSymbolIsNotAValue =
1284+ checkMessagesAfter(" checkStatic" ) {
1285+ """
1286+ |package p
1287+ |object O {
1288+ | val v = p
1289+ |}
1290+ """ .stripMargin
1291+ }.expect { (itcx, messages) =>
1292+ implicit val ctx : Context = itcx
1293+ val JavaSymbolIsNotAValue (symbol) = messages.head
1294+ assertEquals(symbol.show, " package p" )
1295+ }
12821296}
You can’t perform that action at this time.
0 commit comments