Skip to content

HK reduction: Remove special-case for typerefs #1400

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
Jul 19, 2016

Conversation

smarter
Copy link
Member

@smarter smarter commented Jul 18, 2016

The special case:

  case stripped: TypeRef =>
    stripped.symbol.is(BaseTypeArg)

is wrong because you might still want to reduce applications involving
TypeRefs which are not base class parameters, like in:

  class Foo[A]
  type Alias[X] = Foo[X]
  val x: Alias[Int] = ???

Alias is a TypeRef so before this commit Alias[Int] was never reduced
to Foo[Int]. It should have been:

  case stripped: TypeRef if stripped.symbol.is(BaseTypeArg) =>
    true

But even this is incorrect: it assumes that we can always safely reduce HK
applications involving base class parameters, this is not the case when
the parameter kind is different from the rhs kind as illustrated by
i1181c.scala. We fix this by simply dropping the special case.

Review by @odersky

Now that we implement partial higher-order unification (SI-2712 fix)
i1181.scala will compile even if `Alias[Int]` gets dealiased to
`(Int, Int)` because we can unify the latter with `M[_]` where
`M = [X] -> (Int, X)`.

The new test will only succeed if `Alias[Int, Int]` is not dealiased
because we will never unify `Foo[Int]` with `M[_,_]`.
@smarter smarter force-pushed the fix/hk-reduce-typerefs branch 2 times, most recently from b168f9b to 766e4ee Compare July 18, 2016 08:40
The special case:

  case stripped: TypeRef =>
    stripped.symbol.is(BaseTypeArg)

is wrong because you might still want to reduce applications involving
TypeRefs which are not base class parameters, like in:

  class Foo[A]
  type Alias[X] = Foo[X]
  val x: Alias[Int] = ???

`Alias` is a TypeRef so before this commit `Alias[Int]` was never reduced
to `Foo[Int]`. It should have been:

  case stripped: TypeRef if stripped.symbol.is(BaseTypeArg) =>
    true

But even this is incorrect: it assumes that we can always safely reduce HK
applications involving base class parameters, this is not the case when
the parameter kind is different from the rhs kind as illustrated by
`i1181c.scala`. We fix this by simply dropping the special case.
@smarter smarter force-pushed the fix/hk-reduce-typerefs branch from 766e4ee to 6c26344 Compare July 18, 2016 21:34
@smarter
Copy link
Member Author

smarter commented Jul 18, 2016

Oops, had a typo in a test, should be all good now.

@odersky
Copy link
Contributor

odersky commented Jul 19, 2016

LGTM

@odersky odersky merged commit 2193100 into scala:master Jul 19, 2016
@allanrenucci allanrenucci deleted the fix/hk-reduce-typerefs branch December 14, 2017 19:22
@rssh rssh mentioned this pull request Feb 13, 2021
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.

3 participants