Skip to content

Commit 520beb2

Browse files
authored
Merge pull request #15430 from dotty-staging/fix-15428
Make simplify replace type parameters inside method types
2 parents bf026ad + 7ea0d97 commit 520beb2

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,13 @@ object TypeOps:
175175
val normed = tp.tryNormalize
176176
if (normed.exists) normed else mapOver
177177
case tp: MethodicType =>
178-
tp // See documentation of `Types#simplified`
178+
// See documentation of `Types#simplified`
179+
val addTypeVars = new TypeMap:
180+
val constraint = ctx.typerState.constraint
181+
def apply(t: Type): Type = t match
182+
case t: TypeParamRef => constraint.typeVarOfParam(t).orElse(t)
183+
case _ => this.mapOver(t)
184+
addTypeVars(tp)
179185
case tp: SkolemType =>
180186
// Mapping over a skolem creates a new skolem which by definition won't
181187
// be =:= to the original one.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,8 @@ object Types {
18921892
* but its simplification is `Serializable`). This means that simplification
18931893
* should never be used in a `MethodicType`, because that could
18941894
* lead to a different `signature`. Since this isn't very useful anyway,
1895-
* this method handles this by never simplifying inside a `MethodicType`.
1895+
* this method handles this by never simplifying inside a `MethodicType`,
1896+
* except for replacing type parameters with associated type variables.
18961897
*/
18971898
def simplified(using Context): Type = TypeOps.simplify(this, null)
18981899

tests/pos/i15428.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import reflect.Selectable.reflectiveSelectable
2+
3+
trait Foo:
4+
def f(): Long
5+
6+
def h() = k((_: Foo) => ???)
7+
8+
trait Bar[TB]
9+
given Bar[Foo] = ???
10+
11+
def k[Tk, Ptr <: { def f(): Tk }](function: Ptr => Int)(using alloc: Bar[Ptr]): Tk = ???

0 commit comments

Comments
 (0)