diff --git a/convex-core/src/main/java/convex/core/cvm/AFn.java b/convex-core/src/main/java/convex/core/cvm/AFn.java index 8f7efb023..3738f8f43 100644 --- a/convex-core/src/main/java/convex/core/cvm/AFn.java +++ b/convex-core/src/main/java/convex/core/cvm/AFn.java @@ -55,7 +55,6 @@ public byte getTag() { @Override public boolean equals(ACell o) { - if (!(o instanceof AFn)) return false; return Cells.equalsGeneric(this, o); } diff --git a/convex-core/src/main/java/convex/core/lang/impl/AClosure.java b/convex-core/src/main/java/convex/core/lang/impl/AClosure.java index 227098803..9a228b542 100644 --- a/convex-core/src/main/java/convex/core/lang/impl/AClosure.java +++ b/convex-core/src/main/java/convex/core/lang/impl/AClosure.java @@ -20,6 +20,12 @@ protected AClosure(AVector lexicalEnv) { this.lexicalEnv=lexicalEnv; } + @Override + public int encode(byte[] bs, int pos) { + bs[pos++]=getTag(); + return encodeRaw(bs,pos); + } + /** * Produces an copy of this closure with the specified environment * diff --git a/convex-core/src/main/java/convex/core/lang/impl/MultiFn.java b/convex-core/src/main/java/convex/core/lang/impl/MultiFn.java index 36585605e..d74a8ede7 100644 --- a/convex-core/src/main/java/convex/core/lang/impl/MultiFn.java +++ b/convex-core/src/main/java/convex/core/lang/impl/MultiFn.java @@ -98,11 +98,10 @@ public void validateCell() throws InvalidDataException { if (num<=0) throw new InvalidDataException("MultiFn must contain at least one function",this); fns.validateCell(); } - + @Override - public int encode(byte[] bs, int pos) { - bs[pos++]=CVMTag.FN_MULTI; - return encodeRaw(bs,pos); + public byte getTag() { + return CVMTag.FN_MULTI; } @Override @@ -110,7 +109,6 @@ public int encodeRaw(byte[] bs, int pos) { pos = fns.encode(bs,pos); return pos; } - /** * Decodes a MultiFn instance from a Blob encoding diff --git a/convex-core/src/test/java/convex/core/lang/CoreTest.java b/convex-core/src/test/java/convex/core/lang/CoreTest.java index df4d5dace..a8fca7d00 100644 --- a/convex-core/src/test/java/convex/core/lang/CoreTest.java +++ b/convex-core/src/test/java/convex/core/lang/CoreTest.java @@ -4544,6 +4544,9 @@ public void testDefnMulti() { assertEquals(2L,evalL("(do (defn f ([] 4) ([a] 1 2)) (f 3))")); assertArityError(step("(do (defn f ([] nil)) (f 3))")); + + // Check multi-fns capture lexical env + assertEquals(Vectors.of(2,1,2),eval("(do (def a 1) (let [a 2 f (fn ([] a) ([b] (+ a b)))] [a *address*/a (f)]))")); } @Test