Skip to content

Commit db1dc6c

Browse files
committed
SI-4043 Share code in etaExpand and inferPolyAlternatives
Refactors duplication between these methods. I've left the old code with assertions that the old and new results are equivalent, I'll remove these crutches in the subsequent commit.
1 parent 959c5e7 commit db1dc6c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/compiler/scala/tools/nsc/typechecker/Infer.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,8 @@ trait Infer extends Checkable {
14491449
val tparams = newAsSeenFromMap(pre, hd.owner) mapOver hd.typeParams
14501450
val bounds = tparams map (_.tpeHK) // see e.g., #1236
14511451
val tpe = PolyType(tparams, OverloadedType(AntiPolyType(pre, bounds), alts))
1452+
val tpe1 = typeFunAnonSeenFrom(pre, hd, hd.typeParams, (bounds: List[Type]) => OverloadedType(AntiPolyType(pre, bounds), alts))
1453+
assert(tpe.matches(tpe1) && tpe1.matches(tpe1))
14521454
finish(sym setInfo tpe, tpe)
14531455
}
14541456
matchingLength.alternatives match {

src/reflect/scala/reflect/internal/Types.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2184,10 +2184,13 @@ trait Types
21842184
else {
21852185
val map = newAsSeenFromMap(pre, sym.owner)
21862186
val tpars1 = map.mapOver(tpars)
2187-
if (tpars eq tpars1)
2187+
val tp = if (tpars eq tpars1)
21882188
typeFunAnon(tpars, copyTypeRef(this, pre, sym, tpars map (_.tpeHK)))
21892189
else
21902190
typeFunAnon(tpars1, copyTypeRef(this, pre, sym, tpars map (_.tpeHK.substSym(tpars, tpars1))))
2191+
val tp1 = typeFunAnonSeenFrom(pre, sym, tpars, bounds => copyTypeRef(this, pre, sym, bounds))
2192+
assert(tp.matches(tp) && tp1.matches(tp1))
2193+
tp
21912194
} // todo: also beta-reduce?
21922195
}
21932196

@@ -3617,6 +3620,15 @@ trait Types
36173620
/** A creator for a type functions, assuming the type parameters tps already have the right owner. */
36183621
def typeFun(tps: List[Symbol], body: Type): Type = PolyType(tps, body)
36193622

3623+
def typeFunAnonSeenFrom(pre: Type, sym: Symbol, tpars: List[Symbol], body: List[Type] => Type): Type = {
3624+
val map = newAsSeenFromMap(pre, sym.owner)
3625+
val tpars1 = map.mapOver(tpars)
3626+
if (tpars eq tpars1)
3627+
typeFunAnon(tpars, body(tpars map (_.tpeHK)))
3628+
else
3629+
typeFunAnon(tpars1, body(tpars map (_.tpeHK.substSym(tpars, tpars1))))
3630+
}
3631+
36203632
/** A creator for existential types. This generates:
36213633
*
36223634
* tpe1 where { tparams }

0 commit comments

Comments
 (0)