Skip to content

Commit 0a4dca6

Browse files
committed
Polishing
1 parent 035ea54 commit 0a4dca6

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import ErrorMessageID._
2121
import Denotations.SingleDenotation
2222
import dotty.tools.dotc.ast.Trees
2323
import dotty.tools.dotc.config.ScalaVersion
24-
import dotty.tools.dotc.core.Flags.{FlagSet, Mutable}
24+
import dotty.tools.dotc.core.Flags._
2525
import dotty.tools.dotc.core.SymDenotations.SymDenotation
2626
import scala.util.control.NonFatal
2727

@@ -203,11 +203,11 @@ object messages {
203203
val explanation =
204204
hl"""|Anonymous functions must define a type. For example, if you define a function like this one:
205205
|
206-
|${"val f = { case xs @ List(1, 2, 3) => Some(xs) }"}
206+
|${"val f = { case x: Int => x + 1 }"}
207207
|
208208
|Make sure you give it a type of what you expect to match and help the type inference system:
209209
|
210-
|${"val f: Seq[Int] => Option[List[Int]] = { case xs @ List(1, 2, 3) => Some(xs) }"} """
210+
|${"val f: Any => Int = { case x: Int => x + 1 }"} """
211211
}
212212

213213
case class WildcardOnTypeArgumentNotAllowedOnNew()(implicit ctx: Context)
@@ -2078,23 +2078,14 @@ object messages {
20782078
}
20792079

20802080
case class JavaSymbolIsNotAValue(symbol: Symbol)(implicit ctx: Context) extends Message(JavaSymbolIsNotAValueID) {
2081-
val msg = hl"$symbol is not a value"
20822081
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
2082+
val msg = {
2083+
val kind =
2084+
if (symbol is Package) hl"$symbol"
2085+
else hl"Java defined ${"class " + symbol.name}"
20892086

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"""
2087+
s"$kind is not a value"
20982088
}
2089+
val explanation = ""
20992090
}
21002091
}

compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -805,15 +805,15 @@ class ErrorMessagesTests extends ErrorMessagesTest {
805805
checkMessagesAfter("refchecks") {
806806
"""
807807
|object AnonymousF {
808-
| val f = { case l@List(1,2,3) => Some(l) }
808+
| val f = { case x: Int => x + 1 }
809809
|}""".stripMargin
810810
}
811811
.expect { (ictx, messages) =>
812812
implicit val ctx: Context = ictx
813813

814-
val AnonymousFunctionMissingParamType(param, args, _, pt) = messages.last
814+
assertMessageCount(1, messages)
815+
val AnonymousFunctionMissingParamType(param, args, _, pt) = messages.head
815816
assertEquals("x$1", param.show)
816-
assertEquals(s"List(ValDef(${param.show},TypeTree,EmptyTree))", args.toString)
817817
assertEquals("?", pt.show)
818818
}
819819

@@ -1289,6 +1289,8 @@ class ErrorMessagesTests extends ErrorMessagesTest {
12891289
""".stripMargin
12901290
}.expect { (itcx, messages) =>
12911291
implicit val ctx: Context = itcx
1292+
1293+
assertMessageCount(1, messages)
12921294
val JavaSymbolIsNotAValue(symbol) = messages.head
12931295
assertEquals(symbol.show, "package p")
12941296
}

0 commit comments

Comments
 (0)