-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix Java generic signatures for context functions #25632
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ import core.Types.* | |
| import core.classfile.ClassfileConstants | ||
|
|
||
| import config.Printers.transforms | ||
| import dotty.tools.dotc.core.NameOps.isContextFunction | ||
| import reporting.trace | ||
| import java.lang.StringBuilder | ||
|
|
||
|
|
@@ -529,7 +530,14 @@ object GenericSignatures { | |
| @tailrec def recur(tpe: Type): Type = tpe match | ||
| case mtd: MethodType => | ||
| vparams ++= mtd.paramInfos.filterNot(_.hasAnnotation(defn.ErasedParamAnnot)) | ||
| recur(mtd.resType) | ||
| mtd.resType match | ||
| // 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might want to filter out 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems that for method that contains Erased parameter, the result type will be We'd like to pattern match against case defn.FunctionTypeOfMethod(mt: MethodType) if mt.isContextualMethod? |
||
| recur(args.last) | ||
| case _ => | ||
| recur(mtd.resType) | ||
| case PolyType(tps, tpe) => | ||
| tparams ++= tps | ||
| recur(tpe) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| public void CtxFns$.puts(java.lang.Object,CtxFns$Context) | ||
| class java.lang.Object,class CtxFns$Context -> void | ||
| T,class CtxFns$Context -> void | ||
| private java.lang.Object CtxFns$.writeReplace() | ||
| -> class java.lang.Object | ||
| -> class java.lang.Object |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| // scalajs: --skip | ||
| // (this is a JVM-only test) | ||
|
|
||
| object CtxFns { | ||
| abstract class Context: | ||
| def puts[T](t: T): Unit | ||
|
|
||
| def puts[T](t: T): Context ?=> Unit = summon[Context].puts(t) | ||
| } | ||
|
|
||
| object Test: | ||
| def main(args: Array[String]): Unit = | ||
| classOf[CtxFns.type].getDeclaredMethods.sortBy(_.getName).foreach(m => | ||
| println(m) | ||
| println(m.getParameterTypes().mkString(",") + " -> " + m.getReturnType.toString) | ||
| println(m.getGenericParameterTypes().mkString(",") + " -> " + m.getGenericReturnType.toString) | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise, it doesn't catch the following case?