File tree 4 files changed +37
-1
lines changed
test/dotty/tools/dotc/reporting
4 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,7 @@ public enum ErrorMessageID {
126
126
MissingCompanionForStaticID ,
127
127
PolymorphicMethodMissingTypeInParentID ,
128
128
ParamsNoInlineID ,
129
+ JavaSymbolIsNotAValueID ,
129
130
;
130
131
131
132
public int errorNumber () {
Original file line number Diff line number Diff line change @@ -2076,4 +2076,25 @@ object messages {
2076
2076
val msg = hl """ ${" inline" } modifier cannot be used for a ${owner.showKind} parameter """
2077
2077
val explanation = " "
2078
2078
}
2079
+
2080
+ case class JavaSymbolIsNotAValue (symbol : Symbol )(implicit ctx : Context ) extends Message (JavaSymbolIsNotAValueID ) {
2081
+ val msg = hl " $symbol is not a value "
2082
+ val kind = " Type Mismatch"
2083
+ val explanation = {
2084
+ val javaCodeExample = """ class A {public static int a() {return 1;}}"""
2085
+
2086
+ val scalaCodeExample =
2087
+ """ val objectA = A // This does not compile
2088
+ |val aResult = A.a() // This does compile""" .stripMargin
2089
+
2090
+ hl """ Java statics and packages cannot be used as a value.
2091
+ |For Java statics consider the following Java example:
2092
+ |
2093
+ | $javaCodeExample
2094
+ |
2095
+ |When used from Scala:
2096
+ |
2097
+ | $scalaCodeExample"""
2098
+ }
2099
+ }
2079
2100
}
Original file line number Diff line number Diff line change @@ -526,7 +526,7 @@ trait Checking {
526
526
val sym = tree.tpe.termSymbol
527
527
// The check is avoided inside Java compilation units because it always fails
528
528
// on the singleton type Module.type.
529
- if ((sym is Package ) || ((sym is JavaModule ) && ! ctx.compilationUnit.isJava)) ctx.error(em " $ sym is not a value " , tree.pos)
529
+ if ((sym is Package ) || ((sym is JavaModule ) && ! ctx.compilationUnit.isJava)) ctx.error(JavaSymbolIsNotAValue ( sym) , tree.pos)
530
530
}
531
531
tree
532
532
}
Original file line number Diff line number Diff line change @@ -1278,4 +1278,18 @@ class ErrorMessagesTests extends ErrorMessagesTest {
1278
1278
assertEquals(" method get" , rsym.show)
1279
1279
assertEquals(" class Object" , parentSym.show)
1280
1280
}
1281
+
1282
+ @ Test def javaSymbolIsNotAValue =
1283
+ checkMessagesAfter(" checkStatic" ) {
1284
+ """
1285
+ |package p
1286
+ |object O {
1287
+ | val v = p
1288
+ |}
1289
+ """ .stripMargin
1290
+ }.expect { (itcx, messages) =>
1291
+ implicit val ctx : Context = itcx
1292
+ val JavaSymbolIsNotAValue (symbol) = messages.head
1293
+ assertEquals(symbol.show, " package p" )
1294
+ }
1281
1295
}
You can’t perform that action at this time.
0 commit comments