Skip to content
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

Fix clj meta java symbol #89

Merged
merged 2 commits into from
May 25, 2020

Conversation

arichiardi
Copy link
Contributor

@arichiardi arichiardi commented Apr 21, 2020

Before submitting a PR make sure the following things have been done:

  • The commits are consistent with our contribution guidelines
  • You've added tests to cover your change(s)
  • All tests are passing
  • The new code is not generating reflection warnings

Here is the fix that seems to work. Please read the commit message, this is becoming black magic at this point and probably I will need to refactor stuff at some point.
I left the previous function name mostly untouched but given they return info candidates I really think that the java/resolve- prefix does not make too much sense. They probably belong to orchard.info but maybe this deserves another PR.

A treaty could be written on the intricacies of clj-meta. Previously,
java/resolve-symbol was at the end of the chain and was not consulted, cause
conflicts in unqualified names, like max, would result in earlier returns (for
instance of clojure.core/max).

The problem is deeper and moving java/resolve-symbol up would not solve all the
problems, as it is doing two things: returning static member information AND
type information. Basically it broke records and macro refer resolution.

This patch splits that function in two: java/resolve-symbol only checks if
there exist Java members, and java/resolve-type only takes care of full classes
and records.

Interleaving the two with (m/resolve-var unqualified-sym) magically fulfills
all the use cases. There be dragons.
@arichiardi
Copy link
Contributor Author

arichiardi commented Apr 26, 2020

@bbatsov I need a lil' review on this 😉

@bbatsov
Copy link
Member

bbatsov commented Apr 26, 2020

Yeah, certainly. I took a quick look at this PR a few days ago and then I forgot about it. I recall I was a bit confused about the nature of the fix, but it seems it's mostly a matter of doing some checks in a different order. I'll review this more carefully today or tomorrow. A changelog entry is needed, btw.

@@ -323,28 +323,43 @@
(filter identity)
(distinct))))

(defn trim-one-dot
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably this shouldn't be public API. I'm also not sure why exactly do you need this. Remove . from constructors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it was already there, I have just factored it out. I will make it private.

(when-let [ms (seq (resolve-member ns sym*))] ; methodCall
(if (= 1 (count ms))
(first ms)
{:candidates (zipmap (map :class ms) ms)})))))

(defn resolve-type
"Return type info, for a Java class, interface or record."
[ns sym]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably sym is not the best param here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhm, ok Will think about a better name

@@ -425,6 +429,19 @@
(deftest info-java-test
(is (info/info-java 'clojure.lang.Atom 'swap)))

(deftest info-java-member-precendence-test
(testing "Integer/max - issue #86"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't understand what this description means. :-)

@arichiardi
Copy link
Contributor Author

Yes your analysis is correct, we need a different order and interleave. The commit message should contain this info but please let me know if not clear.

@bbatsov
Copy link
Member

bbatsov commented May 18, 2020

The commit message should contain this info but please let me know if not clear.

Yeah, it does, but it's also nice to be able to infer all of this by reading the code, docstrings, etc.

@bbatsov bbatsov merged commit 7445fd1 into clojure-emacs:master May 25, 2020
@arichiardi arichiardi deleted the fix-clj-meta-java-symbol branch May 25, 2020 06:28
@arichiardi
Copy link
Contributor Author

Ooops sorry, got busy, thanks for merging!

@bbatsov
Copy link
Member

bbatsov commented May 25, 2020

@arichiardi Follow up PRs are always welcome as well. ;-) I just plan to cut a new release later this week, so some patch is better than no patch. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants