fix method call reflection
Some checks failed
CI / test-core (14, ubuntu-latest, 3.x, nodejs) (push) Failing after 1m49s
CI / test-core (14, ubuntu-latest, 3.x, py) (push) Failing after 2m14s
CI / test-core (14, ubuntu-latest, 3.x, cpp) (push) Failing after 3m1s
CI / test-core (14, ubuntu-latest, 3.x, interp) (push) Failing after 2m41s
CI / test-core (14, ubuntu-latest, 3.x, js) (push) Failing after 2m21s

This commit is contained in:
2025-09-16 08:29:31 -05:00
parent b441537087
commit 2c22889896

View File

@@ -60,6 +60,8 @@
(evalCC exp.def cc) (evalCC exp.def cc)
(throw "Couldn't read valid expression from $s"))) (throw "Couldn't read valid expression from $s")))
([:ReaderExpDef def] ([:ReaderExpDef def]
// In case it needs to be transformed, pass this
(localVar &mut exp (object pos null def def))
(case def (case def
// Special form call // Special form call
((when (specialForms.exists form) (CallExp (object def (Symbol form)) args)) ((when (specialForms.exists form) (CallExp (object def (Symbol form)) args))
@@ -72,6 +74,7 @@
(cc (Reflect.callMethod null f values))))) (cc (Reflect.callMethod null f values)))))
// Method/function call // Method/function call
((CallExp callable args) ((CallExp callable args)
(transformToFieldExp callable)
(evalCC callable ->f (evalCC callable ->f
(_evalAllCC args ->values (_evalAllCC args ->values
(case callable (case callable
@@ -100,16 +103,9 @@
(cc f) (cc f)
(return))) (return)))
// Check for field access // Check for field access
(let [idx (ident.indexOf ".")] (when (transformToFieldExp exp)
(unless (= -1 idx) (evalCC exp cc)
(let [parts (ident.split ".") (return))
&mut exp (object pos null def (Symbol (first parts)))]
(doFor part (parts.slice 1)
(let [safe (StringTools.startsWith part "?")]
(when safe (set part (part.substr 1)))
(set exp (object pos null def (FieldExp part exp safe)))))
(evalCC exp cc)
(return))))
// Check for ident aliases // Check for ident aliases
(when (identAliases.exists ident) (when (identAliases.exists ident)
(evalCC (dictGet identAliases ident) cc) (evalCC (dictGet identAliases ident) cc)
@@ -131,4 +127,21 @@
(outputs.push v) (outputs.push v)
(_evalAllCC inputs cc outputs) (_evalAllCC inputs cc outputs)
}) })
(cc outputs))) (cc outputs)))
// Check if an identifier has field access in it, return true if transform it to FieldExp
(method transformToFieldExp [:ReaderExp exp]
(case exp.def
((Symbol ident)
(let [idx (ident.indexOf ".")]
(unless (= -1 idx)
(let [parts (ident.split ".")
&mut newExp (object pos null def (Symbol (first parts)))]
(doFor part (parts.slice 1)
(let [safe (StringTools.startsWith part "?")]
(when safe (set part (part.substr 1)))
(set newExp (object pos null def (FieldExp part newExp safe)))))
(set exp.def newExp.def)
(return true)))))
(never otherwise))
false)