File tree 4 files changed +38
-1
lines changed
test/dotty/tools/dotc/reporting
4 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,7 @@ public enum ErrorMessageID {
125
125
UnableToEmitSwitchID ,
126
126
MissingCompanionForStaticID ,
127
127
PolymorphicMethodMissingTypeInParentID ,
128
+ JavaSymbolIsNotAValueID ,
128
129
;
129
130
130
131
public int errorNumber () {
Original file line number Diff line number Diff line change @@ -2069,4 +2069,26 @@ object messages {
2069
2069
| $rsym does not override any method in $parentSym. Structural refinement does not allow for
2070
2070
|polymorphic methods. """
2071
2071
}
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
+
2072
2094
}
Original file line number Diff line number Diff line change @@ -523,7 +523,7 @@ trait Checking {
523
523
val sym = tree.tpe.termSymbol
524
524
// The check is avoided inside Java compilation units because it always fails
525
525
// 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)
527
527
}
528
528
tree
529
529
}
Original file line number Diff line number Diff line change @@ -1279,4 +1279,18 @@ class ErrorMessagesTests extends ErrorMessagesTest {
1279
1279
assertEquals(" method get" , rsym.show)
1280
1280
assertEquals(" class Object" , parentSym.show)
1281
1281
}
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
+ }
1282
1296
}
You can’t perform that action at this time.
0 commit comments