You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
traitTC[T]
objectTC {
defoptionTCForPart[T](implicittc: TC[ExtractPart[T]]):TC[Option[ExtractPart[T]]] =newTC[Option[ExtractPart[T]]] {}
}
typeExtractPart[T] =Tmatch {
casePartField[t] => t
}
typePartField[T] =Any { typePart=T }
classValuePartHolder {
typePart=Value
}
classValueobjectValue {
implicitvaltcValue:TC[Value] =new {}
}
@main defmain():Unit= {
// import Value.tcValue // explicit import works around the issue, but shouldn't be necessaryvaltc=TC.optionTCForPart[ValuePartHolder]
println(tc)
}
Output
valtc=TC.optionTCForPart[ValuePartHolder]
^Nogiveninstance of typeTC[ExtractPart[ValuePartHolder]]
was found for parameter tc of method optionTCForPart in objectTCThe following importmightfixtheproblem:importValue.tcValue
Expectation
Expected to work, since ExtractPart[ValuePartHolder]] evaluates to Value and Value companion object already contains the instance, making explicit import redundant.
The text was updated successfully, but these errors were encountered:
I think this is another cart-before-horse problem. The compiler looks for implicits in the type scope of the match type. It does not reduce the match type at this point. Should it? I am not sure, reducing match types eagerly could cause other problems. For instance, the implicit might force a type variable that is needed to make the match type reduce. The whole area is very finely balanced and everything is a tradeoff in the end.
@odersky
Intuitively I believe it should, e.g. consider a trivial match type type Id[A] = A match { case _ => A }, we'd expect it to behave the same as an equivalent type alias in as much as that's reasonably implementable.
Also, practically, I'm using match types written in the style above - that extract type members - to cross-compile code that uses type projections in Scala 2. So far, I've been able to substitute all usages of general type projections with match types, except for this case - when used together with implicits where the search must find implicits for the extracted type member.
Compiler version
3.3.0-RC5
Minimized code
https://scastie.scala-lang.org/2FKUlvnQTQaY6iZceg9tug
Output
Expectation
Expected to work, since
ExtractPart[ValuePartHolder]]
evaluates toValue
andValue
companion object already contains the instance, making explicit import redundant.The text was updated successfully, but these errors were encountered: