Skip to content

Fix #2770: Tighten type compatibility checks for overrides #2886

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 3 commits into from
Jul 19, 2017

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jul 18, 2017

  • We now require strict subtypes if owning classes are in
    a subclass relationship. Nonempty bounds good enough only
    if classes are unrelated.
  • We treat class types correctly by eta-expanding their types.
  • We do kind checking on types.

Previously, some illegal things slipped through because of the way Any works.
In fact a hk type like [X] => Any is a subtype of Any according to
TypeComparer. But kind checking should prevent us from making that
comparison in the first place.

odersky added 3 commits July 18, 2017 17:51
 - We now require strict subtypes if owning classes are in
   a subclass relationship. Nonempty bounds good enough only
   if classes are unrelated.
 - We treat class types correctly by eta-expanding their types.
 - We do kind checking on types.

Previously, some illegal things slipped through because of the way Any works.
In fact a hk type like `[X] => Any` is a subtype of `Any` according to
TypeComparer. But kind checking should prevent us from making that
comparison in the first place.
Special provisions need to be made if the type argument is a wildcard
or of type Nothing.
Two spurious follow-on errors disappeared
def memberTp(self: Type) =
if (member.isClass) TypeAlias(member.typeRef.EtaExpand(member.typeParams))
else self.memberInfo(member)
def otherTp(self: Type) = self.memberInfo(other)
Copy link
Member

Choose a reason for hiding this comment

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

Why isn't other eta-expanded like member?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other cannot be a class anyway. Classes cannot be overridden.

@odersky odersky merged commit 9b99107 into scala:master Jul 19, 2017
@allanrenucci allanrenucci deleted the fix-#2770-1 branch December 14, 2017 19:18
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