Skip to content

Commit 2db5e2a

Browse files
committed
Drop Show from Any#show extension method
I added this at the last minute as a fallback, but I can't remember the use case exactly, and it muddies the waters by mixing concerns. Also other typo fixes and a code tweak.
1 parent efe0db1 commit 2db5e2a

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

compiler/src/dotty/tools/dotc/core/Decorators.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,16 +251,15 @@ object Decorators {
251251
op: WrappedResult[U] ?=> String,
252252
printer: config.Printers.Printer = config.Printers.default)(using c: Conversion[T, U] = null): T = {
253253
// either the use of `$result` was driven by the expected type of `Shown`
254-
// which lead to the summoning of `Conversion[T, Shown]` (which we'll invoke)
254+
// which led to the summoning of `Conversion[T, Shown]` (which we'll invoke)
255255
// or no such conversion was found so we'll consume the result as it is instead
256256
val obj = if c == null then x.asInstanceOf[U] else c(x)
257257
printer.println(op(using WrappedResult(obj)))
258258
x
259259
}
260260

261261
/** Instead of `toString` call `show` on `Showable` values, falling back to `toString` if an exception is raised. */
262-
def show(using Context)(using z: Show[T] = null): String = x match
263-
case _ if z != null => z.show(x).toString
262+
def show(using Context): String = x match
264263
case x: Showable =>
265264
try x.show
266265
catch

compiler/src/dotty/tools/dotc/printing/Formatting.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ object Formatting {
1616
object ShownDef:
1717
/** Represents a value that has been "shown" and can be consumed by StringFormatter.
1818
* Not just a string because it may be a Seq that StringFormatter will intersperse with the trailing separator.
19-
* Also, it's not a `String | Seq[String]` because then we'd need to a Context to call `Showable#show`. We could
19+
* Also, it's not a `String | Seq[String]` because then we'd need a Context to call `Showable#show`. We could
2020
* make Context a requirement for a Show instance but then we'd have lots of instances instead of just one ShowAny
2121
* instance. We could also try to make `Show#show` require the Context, but then that breaks the Conversion. */
2222
opaque type Shown = Any

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,9 @@ import transform.SymUtils._
17511751

17521752
class ClassAndCompanionNameClash(cls: Symbol, other: Symbol)(using Context)
17531753
extends NamingMsg(ClassAndCompanionNameClashID) {
1754-
def msg = em"Name clash: both ${cls.owner} and its companion object defines ${cls.name.stripModuleClassSuffix.show}"
1754+
def msg =
1755+
val name = cls.name.stripModuleClassSuffix
1756+
em"Name clash: both ${cls.owner} and its companion object defines $name"
17551757
def explain =
17561758
em"""|A ${cls.kindString} and its companion object cannot both define a ${hl("class")}, ${hl("trait")} or ${hl("object")} with the same name:
17571759
| - ${cls.owner} defines ${cls}

0 commit comments

Comments
 (0)