Carp
Carp copied to clipboard
Recursive calls can resolve to meta stubs when meta is foreward declared
To reproduce:
(doc foo "")
(defn foo [x] (if (> x 10) 10 (foo (+ x 1))))
=> I’m unable to concretize the expression '(meta-stub foo)' at line 0, column 0 in 'dummy-file'.
It might be too general. You could try adding a type hint using `the`. at REPL:2:2.
Traceback:
(defn foo [x] (if (> x 10) 10 (foo (+ x 1)))) at REPL:2:1.
When we try to resolve foo in the function body here, we're finding the metastub added to the environment via doc instead of the function definition the recursive call actually wants to refer to. Two possible solutions:
- Fix this so that we don't resolve to the meta stub (entails supporting recursivity in concretize like we do in other modules)
- Add a clause to concretization that understands how to retrieve types from meta stubs (it will initially be typed as a variable, which should be OK).
As a temporary workaround, adding the meta after defining the recursive function works fine.