Skip to content

Commit 0353e64

Browse files
authored
Merge pull request #4083 from dotty-staging/better-gadt-names
Give more meaningful names to GADT type symbols
2 parents def6e0e + d5c285b commit 0353e64

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

compiler/src/dotty/tools/dotc/core/NameKinds.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,14 @@ object NameKinds {
213213
safePrefix + info.num
214214
}
215215

216-
/** Generate fresh unique name of this kind with given prefix name */
216+
/** Generate fresh unique term name of this kind with given prefix name */
217217
def fresh(prefix: TermName = EmptyTermName)(implicit ctx: Context): TermName =
218218
ctx.freshNames.newName(prefix, this)
219219

220+
/** Generate fresh unique type name of this kind with given prefix name */
221+
def fresh(prefix: TypeName)(implicit ctx: Context): TypeName =
222+
fresh(prefix.toTermName).toTypeName
223+
220224
uniqueNameKinds(separator) = this
221225
}
222226

compiler/src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Trees._
99
import Constants._
1010
import Scopes._
1111
import ProtoTypes._
12-
import NameKinds.WildcardParamName
12+
import NameKinds.UniqueName
1313
import annotation.unchecked
1414
import util.Positions._
1515
import util.{Stats, SimpleIdentityMap}
@@ -242,7 +242,7 @@ object Inferencing {
242242
if (bounds.hi <:< bounds.lo || bounds.hi.classSymbol.is(Final) || fromScala2x)
243243
tvar.instantiate(fromBelow = false)
244244
else {
245-
val wildCard = ctx.newPatternBoundSymbol(WildcardParamName.fresh().toTypeName, bounds, pos)
245+
val wildCard = ctx.newPatternBoundSymbol(UniqueName.fresh(tvar.origin.paramName), bounds, pos)
246246
tvar.instantiateWith(wildCard.typeRef)
247247
patternBound += wildCard
248248
}

tests/neg/gadt-eval.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ object Test {
1111
// -- [E007] Type Mismatch Error: tests/neg/gadt-eval.scala:10:6 ------------------
1212
// 10 | (eval(a), eval(a))
1313
// | ^^^^^^^^^^^^^^^^^^
14-
// | found: (_$1, _$1)
14+
// | found: (A$1, A$1)
1515
// | required: T
1616
// |
17-
// | where: T is a type in method eval which is an alias of (_$1, _$2)
17+
// | where: T is a type in method eval which is an alias of (A$1, B$1)
1818
}
1919

2020
def eval2[T](e: Exp[T]): T = e match {

0 commit comments

Comments
 (0)