Clojure

Show type information in reflection warning messages when available

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: Release 1.6
  • Component/s: None
  • Labels:
  • Patch:
    Code and Test
  • Approval:
    Ok

Description

The reflection warning messages currently don't show any type information. I think adding this would make the messages more helpful by making it more obvious what the problem is. I suggest these changes:

(set! *warn-on-reflection* true)

(defn foo [^String x] (.blah x))
Before: reference to field blah can't be resolved.
After:  reference to field blah on java.lang.String can't be resolved.

(defn foo [^String x] (.zap x 1))
Before: call to zap can't be resolved.
After:  call to method zap on java.lang.String can't be resolved (no such method).

(defn foo [] (Integer/valueOf #"boom"))
Before: call to valueOf can't be resolved.
After:  call to static method valueOf on java.lang.Integer can't be resolved (argument types: java.util.regex.Pattern).

(defn foo [x] (Integer/valueOf x))
Before: call to valueOf can't be resolved.
After:  call to static method valueOf on java.lang.Integer can't be resolved (argument types: unknown).

Patch: clj-1248-2.patch

Activity

Alex Miller made changes -
Field Original Value New Value
Approval Triaged [ 10120 ]
Christoffer Sawicki made changes -
Alex Miller made changes -
Description The reflection warning messages currently don't show any type information. I think adding this would make the messages more helpful by making it more obvious what the problem is. I suggest these changes:

{noformat}
(defn foo [^String x] (.blah x))
Current: Reflection warning, NO_SOURCE_PATH:1:23 - reference to field blah can't be resolved.
Suggested: Reflection warning, NO_SOURCE_PATH:1:23 - reference to field java.lang.String.blah can't be resolved.

(defn foo [^String x] (.zap x 1))
Current: Reflection warning, NO_SOURCE_PATH:1:23 - call to zap can't be resolved.
Suggested: Reflection warning, NO_SOURCE_PATH:1:23 - call to java.lang.String.zap can't be resolved.

(defn foo [] (Integer/valueOf #"boom"))
Current: Reflection warning, NO_SOURCE_PATH:1:23 - call to valueOf can't be resolved.
Suggested: Reflection warning, NO_SOURCE_PATH:1:23 - call to java.lang.Integer/valueOf can't be resolved.
{noformat}

Implementation: https://github.com/qerub/clojure/commits/reflection-messages
The reflection warning messages currently don't show any type information. I think adding this would make the messages more helpful by making it more obvious what the problem is. I suggest these changes:

{code}
(defn foo [^String x] (.blah x))
Before: reference to field blah can't be resolved.
After: reference to field blah of java.lang.String can't be resolved.

(defn foo [^String x] (.zap x 1))
Before: call to zap can't be resolved.
After: call to method zap of java.lang.String can't be resolved (no such method).

(defn foo [] (Integer/valueOf #"boom"))
Before: call to valueOf can't be resolved.
After: call to static method valueOf of java.lang.Integer can't be resolved (argument types: [java.util.regex.Pattern]).

(defn foo [x] (Integer/valueOf x))
Before: call to valueOf can't be resolved.
After: call to static method valueOf of java.lang.Integer can't be resolved (argument types: [unknown]).
{code}

*Patch:* {{Include-type-information-in-reflection-warning-messa.patch}}
Alex Miller made changes -
Labels errormsgs
Alex Miller made changes -
Priority Minor [ 4 ] Major [ 3 ]
Alex Miller made changes -
Description The reflection warning messages currently don't show any type information. I think adding this would make the messages more helpful by making it more obvious what the problem is. I suggest these changes:

{code}
(defn foo [^String x] (.blah x))
Before: reference to field blah can't be resolved.
After: reference to field blah of java.lang.String can't be resolved.

(defn foo [^String x] (.zap x 1))
Before: call to zap can't be resolved.
After: call to method zap of java.lang.String can't be resolved (no such method).

(defn foo [] (Integer/valueOf #"boom"))
Before: call to valueOf can't be resolved.
After: call to static method valueOf of java.lang.Integer can't be resolved (argument types: [java.util.regex.Pattern]).

(defn foo [x] (Integer/valueOf x))
Before: call to valueOf can't be resolved.
After: call to static method valueOf of java.lang.Integer can't be resolved (argument types: [unknown]).
{code}

*Patch:* {{Include-type-information-in-reflection-warning-messa.patch}}
The reflection warning messages currently don't show any type information. I think adding this would make the messages more helpful by making it more obvious what the problem is. I suggest these changes:

{code}
(defn foo [^String x] (.blah x))
Before: reference to field blah can't be resolved.
After: reference to field blah on java.lang.String can't be resolved.

(defn foo [^String x] (.zap x 1))
Before: call to zap can't be resolved.
After: call to method zap on java.lang.String can't be resolved (no such method).

(defn foo [] (Integer/valueOf #"boom"))
Before: call to valueOf can't be resolved.
After: call to static method valueOf on java.lang.Integer can't be resolved (argument types: java.util.regex.Pattern).

(defn foo [x] (Integer/valueOf x))
Before: call to valueOf can't be resolved.
After: call to static method valueOf on java.lang.Integer can't be resolved (argument types: unknown).
{code}

*Patch:* clj-1248-2.patch
Attachment clj-1248-2.patch [ 12781 ]
Alex Miller made changes -
Description The reflection warning messages currently don't show any type information. I think adding this would make the messages more helpful by making it more obvious what the problem is. I suggest these changes:

{code}
(defn foo [^String x] (.blah x))
Before: reference to field blah can't be resolved.
After: reference to field blah on java.lang.String can't be resolved.

(defn foo [^String x] (.zap x 1))
Before: call to zap can't be resolved.
After: call to method zap on java.lang.String can't be resolved (no such method).

(defn foo [] (Integer/valueOf #"boom"))
Before: call to valueOf can't be resolved.
After: call to static method valueOf on java.lang.Integer can't be resolved (argument types: java.util.regex.Pattern).

(defn foo [x] (Integer/valueOf x))
Before: call to valueOf can't be resolved.
After: call to static method valueOf on java.lang.Integer can't be resolved (argument types: unknown).
{code}

*Patch:* clj-1248-2.patch
The reflection warning messages currently don't show any type information. I think adding this would make the messages more helpful by making it more obvious what the problem is. I suggest these changes:

{code}
(set! *warn-on-reflection* true)

(defn foo [^String x] (.blah x))
Before: reference to field blah can't be resolved.
After: reference to field blah on java.lang.String can't be resolved.

(defn foo [^String x] (.zap x 1))
Before: call to zap can't be resolved.
After: call to method zap on java.lang.String can't be resolved (no such method).

(defn foo [] (Integer/valueOf #"boom"))
Before: call to valueOf can't be resolved.
After: call to static method valueOf on java.lang.Integer can't be resolved (argument types: java.util.regex.Pattern).

(defn foo [x] (Integer/valueOf x))
Before: call to valueOf can't be resolved.
After: call to static method valueOf on java.lang.Integer can't be resolved (argument types: unknown).
{code}

*Patch:* clj-1248-2.patch
Rich Hickey made changes -
Approval Triaged [ 10120 ] Vetted [ 10003 ]
Fix Version/s Release 1.6 [ 10157 ]
Stuart Halloway made changes -
Approval Vetted [ 10003 ] Screened [ 10004 ]
Rich Hickey made changes -
Approval Screened [ 10004 ] Ok [ 10007 ]
Stuart Halloway made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (12)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: