Skip to content

Commit 7587326

Browse files
mboveltgodzik
authored andcommitted
Copy implementation of SubstMap to IntegrateMap
1 parent 98c9ff6 commit 7587326

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

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

+15-3
Original file line numberDiff line numberDiff line change
@@ -3747,14 +3747,26 @@ object Types extends TypeUtils {
37473747
* result in a [[NoDenotation]], which would make later disambiguation of
37483748
* overloads impossible. See `tests/pos/annot-17242.scala` for example.
37493749
*/
3750-
private class IntegrateMap(params: List[Symbol], paramRefs: List[Type])(using Context) extends TypeMap:
3750+
private class IntegrateMap(from: List[Symbol], to: List[Type])(using Context) extends TypeMap:
37513751
override def apply(tp: Type) =
3752+
// Same implementation as in `SubstMap`, except the `derivedSelect` in
3753+
// the `NamedType` case, and the default case that just calls `mapOver`.
37523754
tp match
3753-
case tp: NamedType if params.contains(tp.symbol) => paramRefs(params.indexOf(tp.symbol))
3755+
case tp: NamedType =>
3756+
val sym = tp.symbol
3757+
var fs = from
3758+
var ts = to
3759+
while (fs.nonEmpty && ts.nonEmpty) {
3760+
if (fs.head eq sym) return ts.head
3761+
fs = fs.tail
3762+
ts = ts.tail
3763+
}
3764+
if (tp.prefix `eq` NoPrefix) tp
3765+
else derivedSelect(tp, apply(tp.prefix))
37543766
case _: BoundType | _: ThisType => tp
37553767
case _ => mapOver(tp)
37563768

3757-
override def derivedSelect(tp: NamedType, pre: Type): Type =
3769+
override final def derivedSelect(tp: NamedType, pre: Type): Type =
37583770
if tp.prefix eq pre then tp
37593771
else if tp.symbol.exists then NamedType(pre, tp.name, tp.denot.asSeenFrom(pre))
37603772
else NamedType(pre, tp.name)

tests/neg/i12448.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
object Main {
22
def mkArray[T <: A]: T#AType // error // error
3-
mkArray[Array] // was: "assertion failed: invalid prefix HKTypeLambda..."
3+
mkArray[Array]
44
val x = mkArray[Array]
55
}

0 commit comments

Comments
 (0)