Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make simplify replace type parameters inside method types #15430

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1890,7 +1890,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 = ???