Conversation
40554be to
9575b0a
Compare
| val implTpeName = Option(impl.tpe).fold("null")(_.toString) | ||
|
|
||
| if (implTpeName.startsWith(forwardPrefix) || | ||
| (implTpeName.startsWith("play.api.libs.json") && |
There was a problem hiding this comment.
I don't think starting with play.api.libs.json proves it's a built-in format. If you use Writes.apply you'll have a class named something like play.api.libs.json.Writes$$anon$6@509f0a9d.
Maybe it's worth just skipping this check and doing the null check for everything?
There was a problem hiding this comment.
Are you sure? I'm pretty sure the lambda is defined in the class it's lexically inside. E.g. if you go to https://alvinalexander.com/scala/anonymous-classes-in-scala-examples and grep for AnonymousClassTest1 you'll see an example.
But I also have no problem with doing a null check for everything since the cost will be low.
There was a problem hiding this comment.
I may be mistaken here, but as I understand it impl is the Tree representing the implementation of the implicit Writes/Reads/Format. So if I have something like:
implicit val fooWrites = Writes[Foo] { foo => JsString(foo.value) }then Play is creating the anonymous class for you based on the lambda you passed. I wouldn't expect impl.tpe to be useful here in identifying Play-provided formats.
There was a problem hiding this comment.
Such factory is instantiating from FunctionalX classes, not excluded from the null-check, contrary to other types from the package
9575b0a to
1050dd5
Compare
| val implTpeName = Option(impl.tpe).fold("null")(_.toString) | ||
|
|
||
| if (implTpeName.startsWith(forwardPrefix) || | ||
| (implTpeName.startsWith("play.api.libs.json") && |
There was a problem hiding this comment.
Are you sure? I'm pretty sure the lambda is defined in the class it's lexically inside. E.g. if you go to https://alvinalexander.com/scala/anonymous-classes-in-scala-examples and grep for AnonymousClassTest1 you'll see an example.
But I also have no problem with doing a null check for everything since the cost will be low.
| !implTpeName.contains("MacroSpec"))) { | ||
| impl // Avoid extra check for builtin formats | ||
| } else { | ||
| q"""_root_.java.util.Objects.requireNonNull($impl, "Invalid implicit resolution (forward reference?) for '" + $cn + "': " + ${implTpeName})""" |
There was a problem hiding this comment.
Invalid implicit resolution -> Implicit value was null?
213db84 to
b0222b1
Compare
|
|
||
| def apply[A](read: JsValue => JsResult[A], write: A => JsObject): OFormat[A] = new OFormat[A] { | ||
| def apply[A](read: JsValue => JsResult[A], write: A => JsObject): OFormat[A] = | ||
| new FunctionalOFormat[A](read, write) |
There was a problem hiding this comment.
Use specific impl class, not to exclude null-check for instances created by these factories
| val implTpeName = Option(impl.tpe).fold("null")(_.toString) | ||
|
|
||
| if (implTpeName.startsWith(forwardPrefix) || | ||
| (implTpeName.startsWith("play.api.libs.json") && |
There was a problem hiding this comment.
Such factory is instantiating from FunctionalX classes, not excluded from the null-check, contrary to other types from the package
| implicit val JsArrayReducer = Reducer[JsValue, JsArray](js => JsArray(Array(js))) | ||
| } | ||
|
|
||
| /** |
|
is anyone interested in pursuing this further, or should we just close it for inactivity? |
b0222b1 to
ab55f42
Compare
|
At least one pull request committer is not linked to a user. See https://help.github.com/en/articles/why-are-my-commits-linked-to-the-wrong-user#commits-are-not-linked-to-any-user |
ab55f42 to
bc570f2
Compare
|
At least one pull request committer is not linked to a user. See https://help.github.com/en/articles/why-are-my-commits-linked-to-the-wrong-user#commits-are-not-linked-to-any-user |
bc570f2 to
02570d0
Compare
|
At least one pull request committer is not linked to a user. See https://help.github.com/en/articles/why-are-my-commits-linked-to-the-wrong-user#commits-are-not-linked-to-any-user |
Fix #120