Skip to content

Commit

Permalink
Merge pull request #15430 from dotty-staging/fix-15428
Browse files Browse the repository at this point in the history
Make simplify replace type parameters inside method types
  • Loading branch information
odersky authored Jun 15, 2022
2 parents bf026ad + 7ea0d97 commit 520beb2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
8 changes: 7 additions & 1 deletion compiler/src/dotty/tools/dotc/core/TypeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,13 @@ object TypeOps:
val normed = tp.tryNormalize
if (normed.exists) normed else mapOver
case tp: MethodicType =>
tp // See documentation of `Types#simplified`
// See documentation of `Types#simplified`
val addTypeVars = new TypeMap:
val constraint = ctx.typerState.constraint
def apply(t: Type): Type = t match
case t: TypeParamRef => constraint.typeVarOfParam(t).orElse(t)
case _ => this.mapOver(t)
addTypeVars(tp)
case tp: SkolemType =>
// Mapping over a skolem creates a new skolem which by definition won't
// be =:= to the original one.
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,8 @@ object Types {
* but its simplification is `Serializable`). This means that simplification
* should never be used in a `MethodicType`, because that could
* lead to a different `signature`. Since this isn't very useful anyway,
* this method handles this by never simplifying inside a `MethodicType`.
* this method handles this by never simplifying inside a `MethodicType`,
* except for replacing type parameters with associated type variables.
*/
def simplified(using Context): Type = TypeOps.simplify(this, null)

Expand Down
11 changes: 11 additions & 0 deletions tests/pos/i15428.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import reflect.Selectable.reflectiveSelectable

trait Foo:
def f(): Long

def h() = k((_: Foo) => ???)

trait Bar[TB]
given Bar[Foo] = ???

def k[Tk, Ptr <: { def f(): Tk }](function: Ptr => Int)(using alloc: Bar[Ptr]): Tk = ???

0 comments on commit 520beb2

Please sign in to comment.