Skip to content

Commit 9bef68c

Browse files
committed
Copy implementation of SubstMap to IntegrateMap
1 parent 2f285a2 commit 9bef68c

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

Diff for: compiler/src/dotty/tools/dotc/core/Types.scala

+15-3
Original file line numberDiff line numberDiff line change
@@ -3840,14 +3840,26 @@ object Types extends TypeUtils {
38403840
* result in a [[NoDenotation]], which would make later disambiguation of
38413841
* overloads impossible. See `tests/pos/annot-17242.scala` for example.
38423842
*/
3843-
private class IntegrateMap(params: List[Symbol], paramRefs: List[Type])(using Context) extends TypeMap:
3843+
private class IntegrateMap(from: List[Symbol], to: List[Type])(using Context) extends TypeMap:
38443844
override def apply(tp: Type) =
3845+
// Same implementation as in `SubstMap`, except the `derivedSelect` in
3846+
// the `NamedType` case, and the default case that just calls `mapOver`.
38453847
tp match
3846-
case tp: NamedType if params.contains(tp.symbol) => paramRefs(params.indexOf(tp.symbol))
3848+
case tp: NamedType =>
3849+
val sym = tp.symbol
3850+
var fs = from
3851+
var ts = to
3852+
while (fs.nonEmpty && ts.nonEmpty) {
3853+
if (fs.head eq sym) return ts.head
3854+
fs = fs.tail
3855+
ts = ts.tail
3856+
}
3857+
if (tp.prefix `eq` NoPrefix) tp
3858+
else derivedSelect(tp, apply(tp.prefix))
38473859
case _: BoundType | _: ThisType => tp
38483860
case _ => mapOver(tp)
38493861

3850-
override def derivedSelect(tp: NamedType, pre: Type): Type =
3862+
override final def derivedSelect(tp: NamedType, pre: Type): Type =
38513863
if tp.prefix eq pre then tp
38523864
else if tp.symbol.exists then NamedType(pre, tp.name, tp.denot.asSeenFrom(pre))
38533865
else NamedType(pre, tp.name)

Diff for: tests/neg/i12448.scala

+2-2
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]
4-
val x = mkArray[Array]
3+
mkArray[Array] // was: "assertion failed: invalid prefix HKTypeLambda..." // error
4+
val x = mkArray[Array] // error
55
}

0 commit comments

Comments
 (0)