Skip to content

Fix #7965: Deal with AndTypes in joins #7992

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 4 commits into from
Jan 15, 2020
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jan 15, 2020

Allow that the base type of a join may be a conjunction.

Allow that the base type of a join may be a conjunction.
@@ -212,6 +212,8 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
tp1.derivedAppliedType(
mergeRefinedOrApplied(tycon1, tycon2),
ctx.typeComparer.lubArgs(args1, args2, tycon1.typeParams))
case AndType(tp21, tp22) =>
Copy link
Member

Choose a reason for hiding this comment

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

This handles having tp1 be an AppliedType and tp2 be an AndType, but it seems that we'd need similar special cases when tp1 is a RefinedType and tp2 is an AndType, etc. Instead maybe all calls to fail in this method could be replaced by a fallback that handles the recursion when tp2 is an AndType.

}
case tp1 @ AppliedType(tycon1, args1) =>
tp2 match {
case AppliedType(tycon2, args2) =>
tp1.derivedAppliedType(
mergeRefinedOrApplied(tycon1, tycon2),
ctx.typeComparer.lubArgs(args1, args2, tycon1.typeParams))
case _ => fail
case _ => fallback
}
case tp1 @ TypeRef(pre1, _) =>
tp2 match {
case tp2 @ TypeRef(pre2, _) if tp1.name eq tp2.name =>
tp1.derivedSelect(pre1 | pre2)
case _ => fail
Copy link
Member

@smarter smarter Jan 15, 2020

Choose a reason for hiding this comment

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

The fallback is also necessary here, otherwise the following would crash:

class Outer {
  class Elem
}

class Test {
  val o1: Outer = ???
  val o2: Outer = ???
  val o3: Outer = ???

  val x: o1.Elem | (o2.Elem & o3.Elem)
  def foo[T <: Outer#Elem](has: T): T = ???
  foo(x)
}

@smarter smarter merged commit 83ab6c7 into scala:master Jan 15, 2020
@smarter smarter deleted the fix-#7965 branch January 15, 2020 18:59
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