Skip to content

Fix #3213: Make PolyTypes generative #3239

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
Oct 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 29 additions & 54 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2599,57 +2599,8 @@ object Types {
final override def toString = s"$prefixString($paramNames, $paramInfos, $resType)"
}

abstract class HKLambda extends CachedProxyType with LambdaType {
final override def underlying(implicit ctx: Context) = resType

final override def computeHash = doHash(paramNames, resType, paramInfos)

// Defined here instead of in LambdaType for efficiency
final override def equals(that: Any) = that match {
case that: HKLambda =>
paramNames == that.paramNames &&
paramInfos == that.paramInfos &&
resType == that.resType &&
companion.eq(that.companion)
case _ =>
false
}

final override def eql(that: Type) = that match {
case that: HKLambda =>
paramNames.equals(that.paramNames) &&
paramInfos.equals(that.paramInfos) &&
resType.equals(that.resType) &&
companion.eq(that.companion)
case _ =>
false
}
}

abstract class MethodOrPoly extends CachedGroundType with LambdaType with MethodicType {
final override def computeHash = doHash(paramNames, resType, paramInfos)

// Defined here instead of in LambdaType for efficiency
final override def equals(that: Any) = that match {
case that: MethodOrPoly =>
paramNames == that.paramNames &&
paramInfos == that.paramInfos &&
resType == that.resType &&
companion.eq(that.companion)
case _ =>
false
}

final override def eql(that: Type) = that match {
case that: MethodOrPoly =>
paramNames.eqElements(that.paramNames) &&
paramInfos.eqElements(that.paramInfos) &&
resType.eq(that.resType) &&
companion.eq(that.companion)
case _ =>
false
}
}
trait HKLambda extends LambdaType
trait MethodOrPoly extends LambdaType with MethodicType

trait TermLambda extends LambdaType { thisLambdaType =>
import DepStatus._
Expand Down Expand Up @@ -2752,7 +2703,7 @@ object Types {
abstract case class MethodType(paramNames: List[TermName])(
paramInfosExp: MethodType => List[Type],
resultTypeExp: MethodType => Type)
extends MethodOrPoly with TermLambda with NarrowCached { thisMethodType =>
extends CachedGroundType with MethodOrPoly with TermLambda with NarrowCached { thisMethodType =>
import MethodType._

type This = MethodType
Expand All @@ -2764,6 +2715,28 @@ object Types {
def computeSignature(implicit ctx: Context): Signature =
resultSignature.prepend(paramInfos, isJava)

final override def computeHash = doHash(paramNames, resType, paramInfos)

final override def equals(that: Any) = that match {
case that: MethodType =>
paramNames == that.paramNames &&
paramInfos == that.paramInfos &&
resType == that.resType &&
companion.eq(that.companion)
case _ =>
false
}

final override def eql(that: Type) = that match {
case that: MethodType =>
paramNames.eqElements(that.paramNames) &&
paramInfos.eqElements(that.paramInfos) &&
resType.eq(that.resType) &&
companion.eq(that.companion)
case _ =>
false
}

protected def prefixString = "MethodType"
}

Expand Down Expand Up @@ -2936,7 +2909,7 @@ object Types {
*/
class HKTypeLambda(val paramNames: List[TypeName])(
paramInfosExp: HKTypeLambda => List[TypeBounds], resultTypeExp: HKTypeLambda => Type)
extends HKLambda with TypeLambda {
extends UncachedProxyType with HKLambda with TypeLambda {
type This = HKTypeLambda
def companion = HKTypeLambda

Expand All @@ -2946,6 +2919,8 @@ object Types {
assert(resType.isInstanceOf[TermType], this)
assert(paramNames.nonEmpty)

final override def underlying(implicit ctx: Context) = resType

protected def prefixString = "HKTypeLambda"
}

Expand All @@ -2954,7 +2929,7 @@ object Types {
*/
class PolyType(val paramNames: List[TypeName])(
paramInfosExp: PolyType => List[TypeBounds], resultTypeExp: PolyType => Type)
extends MethodOrPoly with TypeLambda {
extends UncachedGroundType with MethodOrPoly with TypeLambda {

type This = PolyType
def companion = PolyType
Expand Down
16 changes: 16 additions & 0 deletions tests/pos/i2981.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
trait HList
trait HNil extends HList

trait FromTraversable[Out <: HList]
object FromTraversable {
implicit def hnilFromTraversable[T]: FromTraversable[HNil] =
new FromTraversable[HNil]{}
}

object Filter {
def apply[A <: HList, O <: HList]()(implicit ftA: FromTraversable[A],
ftO: FromTraversable[O]): Unit = ()
}
object Main {
def main = Filter[HNil, HNil]()
}