-
-
Notifications
You must be signed in to change notification settings - Fork 134
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
Forward ref check #136
base: main
Are you sure you want to change the base?
Forward ref check #136
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cchantep can you verify this with a unit test?
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.
That's planned
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid implicit resolution
-> Implicit value was null
?
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.
Updated
213db84
to
b0222b1
Compare
@@ -32,26 +32,27 @@ object OFormat { | |||
|
|||
implicit def GenericOFormat[T](implicit fjs: Reads[T], tjs: OWrites[T]): Format[T] = apply(fjs, tjs) | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such factory is instantiating from FunctionalX
classes, not excluded from the null-check, contrary to other types from the package
@@ -187,44 +190,6 @@ object Reads extends ConstraintReads with PathReads with DefaultReads with Gener | |||
implicit val JsArrayReducer = Reducer[JsValue, JsArray](js => JsArray(Array(js))) | |||
} | |||
|
|||
/** |
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.
Moved down
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