Skip to content

Commit 56feea4

Browse files
committed
Fix #7195: Use superscripts instead of ' for duplicated types
This makes vscode-scala-syntax (and GitHub) highlight error messages correctly. Now it will print ```scala | where: T is a type in object B | T² is a type in object A ``` instead of ```scala | where: T is a type in object B | T' is a type in object A ```
1 parent f44f09f commit 56feea4

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,22 @@ object Formatting {
132132
alts = entry :: existing
133133
update(key, alts)
134134
}
135-
str + "'" * (alts.length - 1)
135+
val suffix = alts.length match {
136+
case 1 => ""
137+
case n => n.toString.toCharArray.map {
138+
case '0' => '⁰'
139+
case '1' => '¹'
140+
case '2' => '²'
141+
case '3' => '³'
142+
case '4' => '⁴'
143+
case '5' => '⁵'
144+
case '6' => '⁶'
145+
case '7' => '⁷'
146+
case '8' => '⁸'
147+
case '9' => '⁹'
148+
}.mkString
149+
}
150+
str + suffix
136151
}
137152
}
138153

tests/neg/i7195.check

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- [E007] Type Mismatch Error: tests/neg/i7195.scala:10:8 --------------------------------------------------------------
2+
10 | A.foo(??? : T) // error
3+
| ^^^^^^^
4+
| Found: B.T
5+
| Required: A.T²
6+
|
7+
| where: T is a type in object B
8+
| T² is a type in object A

tests/neg/i7195.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
object A {
2+
type T
3+
4+
def foo(a: T) = ()
5+
6+
}
7+
8+
object B {
9+
type T
10+
A.foo(??? : T) // error
11+
12+
13+
}

0 commit comments

Comments
 (0)