Skip to content

Commit 04a68b8

Browse files
Merge pull request #7511 from dotty-staging/fix-#7195
Fix #7195: Use superscripts instead of `'` for duplicated types
2 parents 6b739d0 + a39bb0a commit 04a68b8

File tree

4 files changed

+41
-5
lines changed

4 files changed

+41
-5
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

compiler/test-resources/repl/errmsgs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ scala> abstract class C { type T; val x: T; val s: Unit = { type T = String; var
3333
1 | abstract class C { type T; val x: T; val s: Unit = { type T = String; var y: T = x; locally { def f() = { type T = Int; val z: T = y }; f() } }; }
3434
| ^
3535
|Found: C.this.T(C.this.x)
36-
|Required: T'
36+
|Required: T²
3737
|
3838
|where: T is a type in class C
39-
| T' is a type in the initializer of value s which is an alias of String
39+
| T² is a type in the initializer of value s which is an alias of String
4040
1 | abstract class C { type T; val x: T; val s: Unit = { type T = String; var y: T = x; locally { def f() = { type T = Int; val z: T = y }; f() } }; }
4141
| ^
4242
|Found: T(y)
43-
|Required: T'
43+
|Required: T²
4444
|
4545
|where: T is a type in the initializer of value s which is an alias of String
46-
| T' is a type in method f which is an alias of Int
46+
| T² is a type in method f which is an alias of Int
4747
scala> class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
4848
1 | class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
4949
| ^^^^^^^^

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)