-
Notifications
You must be signed in to change notification settings - Fork 57
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
[data] add Render instance for Record (#1008) #1019
[data] add Render instance for Record (#1008) #1019
Conversation
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 is awesome!
val insts = RecordInternal.summonRender[ev.Names, ev.Values] | ||
Render.instance: (value: Record[Fields]) => | ||
value.toMap.map((field, value) => | ||
insts(field.name) match |
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.
Will insts
always contain all values as the map? Is apply
safe here?
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.
It's not safe and there was a bug here because of record subtyping (we may want to print rich record as record with only one field)
I have fixed that and added test
I was about to post a PR generalizing |
builder.toString() | ||
end asText | ||
end new | ||
Render.instance: (value: A) => |
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.
Do we need Render.instance
? I think the compiler can materialize Render
directly from an anonymous function
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.
When I try to to make Render
in inline methods via anonymous function I get compiler warn:
An inline given alias with a function value as right-hand side can significantly increase
generated code size. You should either drop the `inline` or rewrite the given with an
explicit `apply` method.
May be we can just ignore this warn, not sure.
The main reason I've added I think your approach is much better and So, let's finish your PR first, and after that I will fix this PR. |
Cool! I've just posted #1021 |
[data] make `~` an abstract type
b9170e1
to
46d3079
Compare
@@ -432,10 +432,12 @@ class RecordTest extends Test: | |||
""") | |||
} | |||
|
|||
"not compile when fields lack CanEqual" in { | |||
"not compile when fields lack CanEqual" in pendingUntilFixed { // looks like scala3 bug |
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 don't know why this test works in main
When I was fighting with it, I minimized my case to
import scala.compiletime.*
import scala.language.strictEquality
class Lol
object Lol:
inline given CanEqual[Lol, Lol] = error("lol")
val x = new Lol
val y = new Lol
// summon[CanEqual[Lol, Lol]] // doesn't compile
x == y // compile, and this is strange
https://scastie.scala-lang.org/road21/B8hWnSQNTriBcOYndUduRg
For me this looks like a bug in scala3 compiler, what do you think?
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.
yeah, that's odd. I can follow up on this
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 had to extend
FieldsLike
evidence to deriveRender
instances, and now it also contains tuples (types) of names and values.Also I have noticed that an actual type of
~
is never used, so I removed it and now~
is an abstract type member.