diff --git a/convex-core/src/main/cvx/convex/core.cvx b/convex-core/src/main/cvx/convex/core.cvx index 4daee49e6..36d862e16 100644 --- a/convex-core/src/main/cvx/convex/core.cvx +++ b/convex-core/src/main/cvx/convex/core.cvx @@ -201,8 +201,9 @@ (empty? decl) (fail :ARITY "`defn` requires at least one function definition")) (let [fnform (cons 'fn decl) - name (syntax name (meta (first decl)))] ;; Note: merges in metadata on parameter list - `(def ~name ~fnform))) + nf (syntax name (meta (first decl)))] ;; Note: merges in metadata on parameter list + (eval `(def ~name)) ;; ensure we have a forward declaration at expand time + `(def ~nf ~fnform))) (defn identity ^{:doc {:description "An identity function which returns its first argument unchanged." diff --git a/convex-core/src/test/java/convex/core/lang/CompilerTest.java b/convex-core/src/test/java/convex/core/lang/CompilerTest.java index 495e2e301..b93c7616c 100644 --- a/convex-core/src/test/java/convex/core/lang/CompilerTest.java +++ b/convex-core/src/test/java/convex/core/lang/CompilerTest.java @@ -193,10 +193,10 @@ public void testConstantCompilation() { @Test public void testDef() { - assertEquals(2L,evalL("(do (def a 2) (def b 3) a)")); - assertEquals(7L,evalL("(do (def a 2) (def a 7) a)")); - assertEquals(9L,evalL("(do (def a 9) (def a) a)")); - assertEquals(9L,evalL("(do (def a) (def a 9) a)")); + assertCVMEquals(2L,eval("(do (def a 2) (def b 3) a)")); + assertCVMEquals(7L,eval("(do (def a 2) (def a 7) a)")); + assertCVMEquals(9L,eval("(do (def a 9) (def a) a)")); + assertCVMEquals(9L,eval("(do (def a) (def a 9) a)")); assertNull(eval("(do (def a 9) (def a nil) a)")); // TODO: check if these are most logical error types? @@ -205,11 +205,11 @@ public void testConstantCompilation() { } @Test public void testDefOverCore() { - // TODO consider better compilation unit handling in static case - if (!Constants.OPT_STATIC) { - assertEquals(13L,evalL("(do (def count 13) count)")); + // TODO: This might not be sane? + if (Constants.OPT_STATIC) { + assertCVMEquals(Core.COUNT,eval("(do (def count 13) count)")); } else { - assertEquals(Core.COUNT,eval("(do (def count 13) count)")); + assertCVMEquals(13L,eval("(do (def count 13) count)")); } }