Skip to content

Commit c17b68b

Browse files
committed
Fix type aliases in beta-reduction of polyfunctions
Fixes #17052
1 parent e422066 commit c17b68b

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

compiler/src/dotty/tools/dotc/transform/BetaReduce.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ object BetaReduce:
117117
case ref @ TypeRef(NoPrefix, _) =>
118118
ref.symbol
119119
case _ =>
120-
val binding = TypeDef(newSymbol(ctx.owner, tparam.name, EmptyFlags, targ.tpe, coord = targ.span)).withSpan(targ.span)
120+
val binding = TypeDef(newSymbol(ctx.owner, tparam.name, EmptyFlags, TypeAlias(targ.tpe), coord = targ.span)).withSpan(targ.span)
121121
bindings += binding
122122
binding.symbol
123123

compiler/src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,11 @@ object TreeChecker {
533533
i"owner chain = ${tree.symbol.ownersIterator.toList}%, %, ctxOwners = ${ctx.outersIterator.map(_.owner).toList}%, %")
534534
}
535535

536+
override def typedTypeDef(tdef: untpd.TypeDef, sym: Symbol)(using Context): Tree = {
537+
assert(sym.info.isInstanceOf[ClassInfo | TypeBounds], i"wrong type, expect a template or type bounds for ${sym.fullName}, but found: ${sym.info}")
538+
super.typedTypeDef(tdef, sym)
539+
}
540+
536541
override def typedClassDef(cdef: untpd.TypeDef, cls: ClassSymbol)(using Context): Tree = {
537542
val TypeDef(_, impl @ Template(constr, _, _, _)) = cdef: @unchecked
538543
assert(cdef.symbol == cls)

compiler/src/scala/quoted/runtime/impl/printers/SourceCode.scala

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,18 +1345,22 @@ object SourceCode {
13451345
}
13461346

13471347
private def printBoundsTree(bounds: TypeBoundsTree)(using elideThis: Option[Symbol]): this.type = {
1348-
bounds.low match {
1349-
case Inferred() =>
1350-
case low =>
1351-
this += " >: "
1352-
printTypeTree(low)
1353-
}
1354-
bounds.hi match {
1355-
case Inferred() => this
1356-
case hi =>
1357-
this += " <: "
1358-
printTypeTree(hi)
1359-
}
1348+
if bounds.low.tpe == bounds.hi.tpe then
1349+
this += " = "
1350+
printTypeTree(bounds.low)
1351+
else
1352+
bounds.low match {
1353+
case Inferred() =>
1354+
case low =>
1355+
this += " >: "
1356+
printTypeTree(low)
1357+
}
1358+
bounds.hi match {
1359+
case Inferred() => this
1360+
case hi =>
1361+
this += " <: "
1362+
printTypeTree(hi)
1363+
}
13601364
}
13611365

13621366
private def printBounds(bounds: TypeBounds)(using elideThis: Option[Symbol]): this.type = {

tests/pos/i17052.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test[F[_]](fAny: F[Any]) =
2+
{ [X] => (fx: F[X]) => { val fx2: F[X] = fx; () } }.apply[Any](fAny)

0 commit comments

Comments
 (0)