Skip to content

Commit b3d683a

Browse files
committed
Explain skolem types
Strictly speaking, all the info about a skolem type is printed, e.g. A(?2) But it's reassuring to have an explanation line like ?2 is an unknown value of type A
1 parent 529346d commit b3d683a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ object Formatting {
107107
else nonSensicalStartTag + str + nonSensicalEndTag
108108
}
109109

110-
private type Recorded = AnyRef /*Symbol | TypeParamRef*/
110+
private type Recorded = AnyRef /*Symbol | TypeParamRef | SkolemType */
111111

112112
private class Seen extends mutable.HashMap[String, List[Recorded]] {
113113

@@ -135,8 +135,13 @@ object Formatting {
135135
if ((sym is ModuleClass) && sym.sourceModule.exists) simpleNameString(sym.sourceModule)
136136
else seen.record(super.simpleNameString(sym), sym)
137137

138-
override def TypeParamRefNameString(param: TypeParamRef): String =
139-
seen.record(super.TypeParamRefNameString(param), param)
138+
override def ParamRefNameString(param: ParamRef): String =
139+
seen.record(super.ParamRefNameString(param), param)
140+
141+
override def toTextRef(tp: SingletonType): Text = tp match {
142+
case tp: SkolemType => seen.record(tp.repr, tp)
143+
case _ => super.toTextRef(tp)
144+
}
140145
}
141146

142147
/** Create explanation for single `Recorded` type or symbol */
@@ -165,6 +170,8 @@ object Formatting {
165170
s"is a type variable${addendum("constraint", ctx.typeComparer.bounds(param))}"
166171
case sym: Symbol =>
167172
s"is a ${ctx.printer.kindString(sym)}${sym.showExtendedLocation}${addendum("bounds", sym.info)}"
173+
case tp: SkolemType =>
174+
s"is an unknown value of type ${tp.widen.show}"
168175
}
169176
}
170177

@@ -176,6 +183,7 @@ object Formatting {
176183
private def explanations(seen: Seen)(implicit ctx: Context): String = {
177184
def needsExplanation(entry: Recorded) = entry match {
178185
case param: TypeParamRef => ctx.typerState.constraint.contains(param)
186+
case skolem: SkolemType => true
179187
case _ => false
180188
}
181189

0 commit comments

Comments
 (0)