Skip to content

Added error message for Symbol is not a value #1589 #3746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public enum ErrorMessageID {
SymbolChangedSemanticsInVersionID,
UnableToEmitSwitchID,
MissingCompanionForStaticID,
JavaSymbolIsNotAValueID,
;

public int errorNumber() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ object messages {

case class WildcardOnTypeArgumentNotAllowedOnNew()(implicit ctx: Context)
extends Message(WildcardOnTypeArgumentNotAllowedOnNewID) {
val kind = "syntax"
val kind = "Syntax"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only place where this string started with a lowercase. I assumed it was a typo, if somebody could confirm it, it would be good.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good

val msg = "type argument must be fully defined"

val code1 =
Expand Down Expand Up @@ -2064,4 +2064,25 @@ object messages {
val explanation =
hl"An object that contains ${"@static"} members must have a companion class."
}

case class JavaSymbolIsNotAValue(symbol: Symbol)(implicit ctx: Context) extends Message(JavaSymbolIsNotAValueID) {
val msg = hl"$symbol is not a value"
val kind = "Type Mismatch"
val explanation = {
val javaCodeExample = """class A {public static int a() {return 1;}}"""

val scalaCodeExample =
"""val objectA = A // This does not compile
|val aResult = A.a() // This does compile""".stripMargin

hl"""Java statics and packages cannot be used as a value.
|For Java statics consider the following Java example:
|
|$javaCodeExample
|
|When used from Scala:
|
|$scalaCodeExample"""
}
}
}
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ trait Checking {
val sym = tree.tpe.termSymbol
// The check is avoided inside Java compilation units because it always fails
// on the singleton type Module.type.
if ((sym is Package) || ((sym is JavaModule) && !ctx.compilationUnit.isJava)) ctx.error(em"$sym is not a value", tree.pos)
if ((sym is Package) || ((sym is JavaModule) && !ctx.compilationUnit.isJava)) ctx.error(JavaSymbolIsNotAValue(sym), tree.pos)
}
tree
}
Expand Down
14 changes: 14 additions & 0 deletions compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1277,4 +1277,18 @@ class ErrorMessagesTests extends ErrorMessagesTest {
val MissingCompanionForStatic(member) = messages.head
assertEquals(member.show, "method bar")
}

@Test def javaSymbolIsNotAValue =
checkMessagesAfter("checkStatic") {
"""
|package p
|object O {
| val v = p
|}
""".stripMargin
}.expect { (itcx, messages) =>
implicit val ctx: Context = itcx
val JavaSymbolIsNotAValue(symbol) = messages.head
assertEquals(symbol.show, "package p")
}
}