Skip to content

Commit

Permalink
Fix #391, fix regression with variance on Scala 3.3.0. Use fixes from s…
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-kai committed May 30, 2023
1 parent ffa7d96 commit 6c243fb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,16 @@ abstract class Inspector(protected val shift: Int, val context: Queue[Inspector.
case Nil =>
makeNameReferenceFromType(appliedType.tycon)
case _ =>
val symbolVariances = appliedType.tycon.typeSymbol.typeMembers.map(extractVariance)
val symbolVariances = appliedType.tycon.typeSymbol.typeMembers.collect {
case s if s.isTypeParam =>
extractVariance(s)
}
val variances = if (symbolVariances.sizeCompare(appliedType.args) < 0) {
appliedType.tycon match {
case typeParamRef: ParamRef =>
typeParamRef._underlying match {
case TypeBounds(_, hi) =>
hi._declaredVariancesIfHKTypeLambda.fold(Nil)(_.map(extractVariance))
hi._paramVariancesIfHKTypeLambda.fold(Nil)(_.map(extractVariance))
case _ =>
Nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private[dottyreflection] trait ReflectionUtil { this: InspectorBase =>
}

import ReflectionUtil.reflectiveUncheckedNonOverloadedSelectable
import InternalContext.InternalContext

extension (typeRef: TypeRef | ParamRef) {
protected final def _underlying: TypeRepr = {
Expand All @@ -102,14 +103,16 @@ private[dottyreflection] trait ReflectionUtil { this: InspectorBase =>
// )
// underlying.asInstanceOf[TypeRepr]

typeRef.asInstanceOf[InternalTypeRefOrParamRef].underlying(using qctx._ctx)
typeRef.asInstanceOf[InternalTypeRefOrParamRef].underlying(qctx._ctx)
}
}

extension (typeRepr: TypeRepr) {
protected final def _declaredVariancesIfHKTypeLambda: Option[List[Flags]] = {
protected final def _paramVariancesIfHKTypeLambda: Option[List[Flags]] = {
try {
Some(typeRepr.asInstanceOf[InternalHKTypeLambda].declaredVariances)
val params = typeRepr.asInstanceOf[InternalHKTypeLambda].typeParams
val flags = params.map(_.paramVariance(qctx._ctx))
Some(flags)
} catch {
case _: NoSuchMethodException => None
}
Expand Down Expand Up @@ -208,14 +211,20 @@ private[dottyreflection] trait ReflectionUtil { this: InspectorBase =>
}

type InternalTypeRefOrParamRef = {
def underlying(using InternalContext): TypeRepr
def underlying(ctx: InternalContext): TypeRepr
}

type InternalHKTypeLambda = {
def declaredVariances: List[Flags]
val typeParams: List[InternalLambdaParam]
}

opaque type InternalContext = Any
type InternalLambdaParam = {
def paramVariance(ctx: InternalContext): Flags
}

object InternalContext {
opaque type InternalContext = Any
}

}

Expand Down

0 comments on commit 6c243fb

Please sign in to comment.