Skip to content

Fix checking whether types are instantiable. #668

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
Jun 22, 2015
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jun 19, 2015

The logic for checking aginst the self type was wrong, as demonstrated
by pos/checkInstantiable.scala. Review by @retronym.

The logic for checking aginst the self type was wrong, as demonstrated
by pos/checkInstantiable.scala.
if (selfType.exists && !(tp <:< selfType))
// Create a synthetic singleton type instance, and check whether
// it conforms to the self type of the class as seen from that instance.
val stp = SkolemType(tp)
Copy link
Member

Choose a reason for hiding this comment

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

Am I right in assuming that this is similar to tp.narrow in scalac?

Copy link
Member

Choose a reason for hiding this comment

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

In those terms, this LGTM, although I must admit I wouldn't have been able to come up with this formulation myself.

scala> class LS[T] { self: LS[T] => }
defined class LS

scala> val cls = symbolOf[LS[_]]
cls: $r.intp.global.TypeSymbol = class LS

scala> val tp = typeOf[LS[Any]]
tp: $r.intp.global.Type = LS[Any]

scala> val stp = tp.narrow
stp: $r.intp.global.Type = <refinement>.type

scala> val selfType = cls.selfType.asSeenFrom(stp, cls)
selfType: $r.intp.global.Type = LS[Any]

scala> stp <:< selfType
res7: Boolean = true

vs

scala> class LS[T] { self: LS[T with String] => }
defined class LS

scala> val tp = typeOf[LS[Any]]
tp: $r.intp.global.Type = LS[Any]

scala> val cls = symbolOf[LS[_]]
cls: $r.intp.global.TypeSymbol = class LS

scala> val selfType = cls.selfType.asSeenFrom(stp, cls)
selfType: $r.intp.global.Type = LS[T with String]

scala> stp <:< selfType
res8: Boolean = false

@odersky
Copy link
Contributor Author

odersky commented Jun 22, 2015

@retronym SkolemType is indeed a cheaper version of narrow. It took some iterations and dead ends to come up with the current formulation of checkInstantiable.

odersky added a commit that referenced this pull request Jun 22, 2015
Fix checking whether types are instantiable.
@odersky odersky merged commit f03f5b0 into master Jun 22, 2015
@felixmulder felixmulder deleted the fix/#650-self-types branch September 14, 2016 08:41
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