Skip to content

Commit 263a41d

Browse files
committed
feat: if field-overload, convert to method-value
1 parent c472415 commit 263a41d

1 file changed

Lines changed: 33 additions & 10 deletions

File tree

src/main/clojure/clojure/tools/analyzer/passes/jvm/process_method_value.clj

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,20 @@
1212

1313
(defn process-method-value
1414
"Transforms :invoke nodes whose :fn is a :method-value into the
15-
corresponding :instance-call, :static-call, or :new node. "
15+
corresponding :instance-call, :static-call, or :new node.
16+
Also converts value-position :method-value nodes with a
17+
:field-overload (and no :param-tags) into :static-field nodes."
1618
{:pass-info {:walk :post :depends #{#'analyze-host-expr}}}
1719
[{:keys [op args env] :as ast}]
18-
(if (and (= :invoke op)
19-
(= :method-value (:op (:fn ast))))
20-
(let [{:keys [class method kind param-tags]} (:fn ast)]
21-
(when (and (= :instance kind) (empty? args))
20+
(cond
21+
(and (= :invoke op)
22+
(= :method-value (:op (:fn ast))))
23+
(let [{:keys [class method kind param-tags methods]} (:fn ast)
24+
instance? (= :instance kind)
25+
call-args (if instance? (vec (rest args)) args)
26+
argc (count call-args)
27+
methods (seq (filter #(= argc (count (:parameter-types %))) methods))]
28+
(when (and instance? (empty? args))
2229
(throw (ex-info (str "Qualified instance method " (.getName ^Class class) "/." method
2330
" must have a target")
2431
(merge {:class class :method method}
@@ -30,22 +37,38 @@
3037
:method method
3138
:class class
3239
:instance (first args)
33-
:args (vec (rest args))
40+
:args call-args
3441
:children [:instance :args]}
3542

3643
:static
3744
{:op :static-call
3845
:method method
3946
:class class
40-
:args args
47+
:args call-args
4148
:children [:args]}
4249

4350
:ctor
4451
{:op :new
4552
:class {:op :const :type :class :val class
4653
:form class :env env}
47-
:args args
54+
:args call-args
4855
:children [:class :args]})
4956
(when param-tags
50-
{:param-tags param-tags})))
51-
ast))
57+
{:param-tags param-tags})
58+
(when methods
59+
{:methods (vec methods)})))
60+
61+
(and (= :method-value op)
62+
(:field-overload ast)
63+
(not (:param-tags ast)))
64+
(let [{:keys [flags type name]} (:field-overload ast)]
65+
{:op :static-field
66+
:assignable? (not (:final flags))
67+
:class (:class ast)
68+
:field name
69+
:form (:form ast)
70+
:env env
71+
:o-tag type
72+
:tag (or (:tag ast) type)})
73+
74+
:else ast))

0 commit comments

Comments
 (0)