Fix Java generic signatures for context functions#25632
Fix Java generic signatures for context functions#25632SolalPirelli wants to merge 2 commits intoscala:mainfrom
Conversation
tanishiking
left a comment
There was a problem hiding this comment.
Nice catch! I left some concerns but otherwise looks good
| // Returned context functions are erased by putting their parameters into the method's parameters, | ||
| // so we must duplicate that logic here | ||
| case AppliedType(tycon, args) if tycon.typeSymbol.name.isContextFunction => | ||
| vparams ++= args.take(args.length - 1) |
There was a problem hiding this comment.
We might want to filter out .filterNot(_.hasAnnotation(defn.ErasedParamAnnot)) similar to for normal parameters, otherwise, erased type parameter will remain in generic signature, while it is removed in descriptor ?
import language.experimental.erasedDefinitions
class CanSerialize extends compiletime.Erased
object Test:
trait Ctx
def foo(x: Int): CanSerialize ?=> Ctx ?=> String = "foo"(I didn't know about this feature until I see the vparams ++= mtd.paramInfos.filterNot(_.hasAnnotation(defn.ErasedParamAnnot)) line above :p
https://docs.scala-lang.org/scala3/reference/experimental/erased-defs.html
There was a problem hiding this comment.
it seems that for method that contains Erased parameter, the result type will be RefinedType instead of AppliedType.
We'd like to pattern match against
case defn.FunctionTypeOfMethod(mt: MethodType) if mt.isContextualMethod?
| case mtd: MethodType => | ||
| vparams ++= mtd.paramInfos.filterNot(_.hasAnnotation(defn.ErasedParamAnnot)) | ||
| recur(mtd.resType) | ||
| mtd.resType match |
There was a problem hiding this comment.
| mtd.resType match | |
| mtd.resType.dealias match |
otherwise, it doesn't catch the following case?
object Test:
trait Ctx
type Handler = Ctx ?=> String
def foo(x: Int): Handler = "hello"
Fixes #10039
How much have you relied on LLM-based tools in this contribution?
not
How was the solution tested?
test from the issue turned into a fully automated one