Skip to content

Commit a085de5

Browse files
authored
Merge pull request #13372 from adpi2/fix-13306
Print the type parameter bounds of higher kinded types
2 parents 8bb0ca7 + 7e27c2c commit a085de5

File tree

4 files changed

+52
-24
lines changed

4 files changed

+52
-24
lines changed

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,17 @@ class PlainPrinter(_ctx: Context) extends Printer {
348348
case None => "?"
349349
}
350350

351-
protected def decomposeLambdas(bounds: TypeBounds): (String, TypeBounds) =
352-
def decompose(tp: Type) = tp.stripTypeVar match
351+
protected def decomposeLambdas(bounds: TypeBounds): (Text, TypeBounds) =
352+
def decompose(tp: Type): (Text, Type) = tp.stripTypeVar match
353353
case lam: HKTypeLambda =>
354354
val names =
355355
if lam.isDeclaredVarianceLambda then
356356
lam.paramNames.lazyZip(lam.declaredVariances).map((name, v) =>
357357
varianceSign(v) + name)
358-
else lam.paramNames
359-
(names.mkString("[", ", ", "]"), lam.resType)
358+
else lam.paramNames.map(_.toString)
359+
val infos = lam.paramInfos.map(toText)
360+
val tparams = names.zip(infos).map(_ ~ _)
361+
("[" ~ Text(tparams, ",") ~ "]", lam.resType)
360362
case _ =>
361363
("", tp)
362364
bounds match

tests/neg-custom-args/i11637.check

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
-- [E057] Type Mismatch Error: tests/neg-custom-args/i11637.scala:11:33 ------------------------------------------------
22
11 | var h = new HKT3_1[FunctorImpl](); // error // error
33
| ^
4-
| Type argument test2.FunctorImpl does not conform to upper bound [Generic2[T] <: Set[T]] =>> Any
4+
| Type argument test2.FunctorImpl does not conform to upper bound [Generic2[T <: String] <: Set[T]] =>> Any
55

66
Explanation
77
===========
88

99
I tried to show that
1010
test2.FunctorImpl
1111
conforms to
12-
[Generic2[T] <: Set[T]] =>> Any
12+
[Generic2[T <: String] <: Set[T]] =>> Any
1313
but the comparison trace ended with `false`:
1414

15-
==> test2.FunctorImpl <: [Generic2[T] <: Set[T]] =>> Any
16-
==> test2.FunctorImpl <: [Generic2[T] <: Set[T]] =>> Any (recurring)
17-
==> type bounds [[T] <: Set[T]] <: type bounds [[T] <: Iterable[T]]
18-
==> type bounds [[T] <: Set[T]] <: type bounds [[T] <: Iterable[T]] (recurring)
15+
==> test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any
16+
==> test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any (recurring)
17+
==> type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]]
18+
==> type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] (recurring)
1919
==> [T <: String] =>> Set[T] <: Iterable
2020
==> [T <: String] =>> Set[T] <: Iterable (recurring)
2121
==> type bounds [] <: type bounds [ <: String]
@@ -30,31 +30,31 @@ but the comparison trace ended with `false`:
3030
<== type bounds [] <: type bounds [ <: String] = false
3131
<== [T <: String] =>> Set[T] <: Iterable (recurring) = false
3232
<== [T <: String] =>> Set[T] <: Iterable = false
33-
<== type bounds [[T] <: Set[T]] <: type bounds [[T] <: Iterable[T]] (recurring) = false
34-
<== type bounds [[T] <: Set[T]] <: type bounds [[T] <: Iterable[T]] = false
35-
<== test2.FunctorImpl <: [Generic2[T] <: Set[T]] =>> Any (recurring) = false
36-
<== test2.FunctorImpl <: [Generic2[T] <: Set[T]] =>> Any = false
33+
<== type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] (recurring) = false
34+
<== type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] = false
35+
<== test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any (recurring) = false
36+
<== test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any = false
3737

3838
The tests were made under the empty constraint
3939

4040
-- [E057] Type Mismatch Error: tests/neg-custom-args/i11637.scala:11:21 ------------------------------------------------
4141
11 | var h = new HKT3_1[FunctorImpl](); // error // error
4242
| ^
43-
| Type argument test2.FunctorImpl does not conform to upper bound [Generic2[T] <: Set[T]] =>> Any
43+
| Type argument test2.FunctorImpl does not conform to upper bound [Generic2[T <: String] <: Set[T]] =>> Any
4444

4545
Explanation
4646
===========
4747

4848
I tried to show that
4949
test2.FunctorImpl
5050
conforms to
51-
[Generic2[T] <: Set[T]] =>> Any
51+
[Generic2[T <: String] <: Set[T]] =>> Any
5252
but the comparison trace ended with `false`:
5353

54-
==> test2.FunctorImpl <: [Generic2[T] <: Set[T]] =>> Any
55-
==> test2.FunctorImpl <: [Generic2[T] <: Set[T]] =>> Any (recurring)
56-
==> type bounds [[T] <: Set[T]] <: type bounds [[T] <: Iterable[T]]
57-
==> type bounds [[T] <: Set[T]] <: type bounds [[T] <: Iterable[T]] (recurring)
54+
==> test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any
55+
==> test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any (recurring)
56+
==> type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]]
57+
==> type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] (recurring)
5858
==> [T <: String] =>> Set[T] <: Iterable
5959
==> [T <: String] =>> Set[T] <: Iterable (recurring)
6060
==> type bounds [] <: type bounds [ <: String]
@@ -69,9 +69,9 @@ but the comparison trace ended with `false`:
6969
<== type bounds [] <: type bounds [ <: String] = false
7070
<== [T <: String] =>> Set[T] <: Iterable (recurring) = false
7171
<== [T <: String] =>> Set[T] <: Iterable = false
72-
<== type bounds [[T] <: Set[T]] <: type bounds [[T] <: Iterable[T]] (recurring) = false
73-
<== type bounds [[T] <: Set[T]] <: type bounds [[T] <: Iterable[T]] = false
74-
<== test2.FunctorImpl <: [Generic2[T] <: Set[T]] =>> Any (recurring) = false
75-
<== test2.FunctorImpl <: [Generic2[T] <: Set[T]] =>> Any = false
72+
<== type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] (recurring) = false
73+
<== type bounds [[T <: String] <: Set[T]] <: type bounds [[T] <: Iterable[T]] = false
74+
<== test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any (recurring) = false
75+
<== test2.FunctorImpl <: [Generic2[T <: String] <: Set[T]] =>> Any = false
7676

7777
The tests were made under the empty constraint

tests/printing/i13306.check

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[[syntax trees at end of typer]] // tests/printing/i13306.scala
2+
package example {
3+
class MyClass() extends Object() {}
4+
class MembersContainer() extends Object() {
5+
type MyType[T >: Nothing <: example.MyClass] = Comparable[T]
6+
}
7+
final lazy module val Exports: example.Exports = new example.Exports()
8+
final module class Exports() extends Object() { this: example.Exports.type =>
9+
val instance: example.MembersContainer = new example.MembersContainer()
10+
export example.Exports.instance.*
11+
final type MyType[T <: example.MyClass] = Comparable[T]
12+
}
13+
}
14+

tests/printing/i13306.scala

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package example
2+
3+
class MyClass
4+
5+
class MembersContainer {
6+
type MyType[T <: MyClass] = Comparable[T]
7+
}
8+
9+
object Exports {
10+
val instance = new MembersContainer
11+
export instance.*
12+
}

0 commit comments

Comments
 (0)