Skip to content

SI-7753 InstantiateDependentMap narrows type of unstable args #3518

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 1 commit into from
Feb 13, 2014

Conversation

adriaanm
Copy link
Contributor

Rebase of #3507, already LGTM'ed over there.

[Most of this comment and the initial fix were implemented by Jason Zaugg.
I just cleaned it up a bit.]

After a soundness fix in , instantiation of dependent
method type results behaved differently depending on whether the argument
from which we were propagating information had a stable type
or not. This is particular to substitution into singleton types
over the parameter in question.

If the argument was stable, it was substituted into singleton
types, such as the one below in the prefix in a.type#B
(which is the longhand version of a.B)

scala> class A { type B >: Null <: AnyRef }
defined class A

scala> object AA extends A { type B = String }
defined object AA

scala> def foo(a: A): a.B = null
foo: (a: A)a.B

scala> foo(AA)
res0: AA.B = null

But what if it isn't stable?

scala> foo({def a = AA; a: A { type B <: String}})
res1: a.B = null

This commit changes that to:

scala> foo({def a = AA; a: A { type B <: String}})
res1: A{type B <: String}#B = null

[Most of this comment and the initial fix were implemented by Jason Zaugg.
I just cleaned it up a bit.]

After a soundness fix in SI-3873, instantiation of dependent
method type results behaved differently depending on whether the argument
from which we were propagating information had a stable type
or not. This is particular to substitution into singleton types
over the parameter in question.

If the argument was stable, it was substituted into singleton
types, such as the one below in the prefix in `a.type#B`
(which is the longhand version of `a.B`)

  scala> class A { type B >: Null <: AnyRef }
  defined class A

  scala> object AA extends A { type B = String }
  defined object AA

  scala> def foo(a: A): a.B = null
  foo: (a: A)a.B

  scala> foo(AA)
  res0: AA.B = null

But what if it isn't stable?

  scala> foo({def a = AA; a: A { type B <: String}})
  res1: a.B = null

This commit changes that to:

  scala> foo({def a = AA; a: A { type B <: String}})
  res1: A{type B <: String}#B = null
@adriaanm
Copy link
Contributor Author

LGTM (proxied from #3507)

adriaanm added a commit that referenced this pull request Feb 13, 2014
SI-7753 InstantiateDependentMap narrows type of unstable args
@adriaanm adriaanm merged commit c0edf76 into scala:master Feb 13, 2014
@adriaanm
Copy link
Contributor Author

Forgot to mention this also fixes SI-8223

@retronym
Copy link
Member

An unforseen consequence of inferring the existential: milessabin/shapeless#79

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