From b8c9d5a845f01bb947ebef7edb37fd8e5de993dc Mon Sep 17 00:00:00 2001 From: Chris Kipp Date: Tue, 29 Mar 2022 10:00:34 +0200 Subject: [PATCH] fix: correct highlight interpolation in explain message Currently the output of `explain` when you are missing a return type in an abstract declaration looks like this: ``` scala> trait Foo: | def foo -- [E019] Syntax Error: -------------------------------------------------------- 2 | def foo | ^ | Missing return type |----------------------------------------------------------------------------- | Explanation (enabled by `-explain`) |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | An abstract declaration must have a return type. For example: | | trait Shape {hl( | def area: Double // abstract declaration returning a Double | )} ----------------------------------------------------------------------------- ``` This fixes the interpolation issue so the return correctly shows: ``` scala> trait Foo: | def foo -- [E019] Syntax Error: -------------------------------------------------------- 2 | def foo | ^ | Missing return type |----------------------------------------------------------------------------- | Explanation (enabled by `-explain`) |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | An abstract declaration must have a return type. For example: | | trait Shape: | def area: Double // abstract declaration returning a Double ----------------------------------------------------------------------------- ``` The `def area: Double` is now also correctly colored. --- compiler/src/dotty/tools/dotc/reporting/messages.scala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/reporting/messages.scala b/compiler/src/dotty/tools/dotc/reporting/messages.scala index e1f05cbdb8a9..8e494ab3b40d 100644 --- a/compiler/src/dotty/tools/dotc/reporting/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/messages.scala @@ -589,9 +589,8 @@ import transform.SymUtils._ def explain = em"""|An abstract declaration must have a return type. For example: | - |trait Shape {hl( - | def area: Double // abstract declaration returning a ${"Double"} - |)}""" + |trait Shape: + | ${hl("def area: Double")} // abstract declaration returning a Double""" } class MissingReturnTypeWithReturnStatement(method: Symbol)(using Context)