-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add Symbol.defaultParams and Expr.mapOf* family of methods #9236
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
Conversation
compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala
Outdated
Show resolved
Hide resolved
compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,4 @@ | |||
case class Cat(name: String, address: String = "Home", age: Int = 1) |
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.
This case is trivial. We should add more complex tests like
case class Cat(name: String, address: String = "Home", age: Int = 1)(a: Int = age, b: String = address + age)
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.
I've added a clarification in the docs that currently we are working only against the first argument group. Trying to trivially return symbols for the defs of the other argument groups' params yielded crashes on testing.
compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala
Outdated
Show resolved
Hide resolved
@@ -1332,6 +1332,11 @@ trait CompilerInterface { | |||
/** Fields of a case class type -- only the ones declared in primary constructor */ | |||
def Symbol_caseFields(self: Symbol)(using ctx: Context): List[Symbol] | |||
|
|||
/** Default parameters of a case class. Keys are names of the parameters and values – |
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.
Why only for case classes? We should check what happens with methods and other constructors.
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.
The implementation works against companions of case classes. I believe for methods, the logic will not work out of the box and will have to be modified.
I would prefer to take it one step at a time: the most trivial implementation first and more complex will follow. With the current implementation, we can already do something porting-wise. We can create an issue for more advanced features like more argument groups (and the discussion of how exactly that should work) or default params of method symbols.
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.
Then it should be called caseClassDefaultParams
.
e5c9790
to
733d196
Compare
For some reason it fails the Community Build. FTTB disable it as a hotfix.
Co-authored-by: Nicolas Stucki <nicolas.stucki@gmail.com> Update tests
Update tests
733d196
to
d991b85
Compare
On top #9279 |
defaultParams.map { case (k, v) => Ref(v).seal } | ||
val names: List[Expr[String]] = | ||
defaultParams.map { case (k, v) => Expr(k) } | ||
'{ ${ Expr.ofList(names) }.zip(${ Expr.ofList(values) }) } |
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.
Don't zip in the next stage and use the Expr.ofList
constructor.
'{ ${ Expr.ofList(names) }.zip(${ Expr.ofList(values) }) } | |
Expr.ofList(names.zip(values).map { case (n, v) => '{ ($n, $v) } }) |
* are returned. | ||
*/ | ||
def defaultParams(using ctx: Context): List[(String, Symbol)] = | ||
internal.Symbol_defaultParams(sym) |
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.
Try to move the implementation here. There is no reason to add it to the CompilerInterface
if it can be computed using it.
No description provided.