Skip to content

Fix #5844: Use an approximating type map to substitute parent type params #5899

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

Merged
merged 2 commits into from
Feb 16, 2019

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Feb 11, 2019

Actual arguments could be wildcards, which means a normal substitution will not work.

Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit restrictive to me, e.g. the following works in Scala 2:

trait A
trait B[X]{
  def m(): X
}
trait C[X] extends B[X with A]

object O{
  def m(c: C[_]) = {
    val x: A = c.m()
  }
}

But will fail with this PR. I think we could preserve this by normalizing like this:

X & _    ~>   X
X | _    ~>   _

@smarter
Copy link
Member

smarter commented Feb 13, 2019

Thinking about it more, this seems like a job for ApproximatingTypeMap.

…pe params

Actual arguments could be wildcards, which means a normal substitution will
not work.
@odersky odersky changed the title Fix #5844: Sanitize base type before substituting wildcard arguments Fix #5844: Use an approximating type map to substitute parent type params Feb 15, 2019
@@ -195,4 +195,28 @@ trait Substituters { this: Context =>
final class SubstParamsMap(from: BindingType, to: List[Type]) extends DeepTypeMap {
def apply(tp: Type): Type = substParams(tp, from, to, this)
}

/** An approximating substitution that can handle wildcards in the `to` list */
final class SubstApproxMap(from: List[Symbol], to: List[Type])(implicit ctx: Context) extends ApproximatingTypeMap {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regular SubstBindingMap also extends DeepTypeMap, does this matter here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we do not need to substitute ClassInfos here.

@smarter smarter merged commit 12eef6d into scala:master Feb 16, 2019
@allanrenucci allanrenucci deleted the fix-#5844 branch February 16, 2019 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants