Skip to content

Commit

Permalink
fix: correct highlight interpolation in explain message
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ckipp01 committed Mar 29, 2022
1 parent 441afc5 commit b8c9d5a
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b8c9d5a

Please sign in to comment.