Skip to content

Commit 59889fd

Browse files
bronsastuarthalloway
authored andcommitted
fix AOT bug preventing overriding of clojure.core functions
Signed-off-by: Stuart Halloway <stu@cognitect.com>
1 parent d00f7c2 commit 59889fd

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/jvm/clojure/lang/Compiler.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ static class DefExpr implements Expr{
392392
public final Expr meta;
393393
public final boolean initProvided;
394394
public final boolean isDynamic;
395+
public final boolean shadowsCoreMapping;
395396
public final String source;
396397
public final int line;
397398
public final int column;
@@ -400,15 +401,17 @@ static class DefExpr implements Expr{
400401
final static Method setMetaMethod = Method.getMethod("void setMeta(clojure.lang.IPersistentMap)");
401402
final static Method setDynamicMethod = Method.getMethod("clojure.lang.Var setDynamic(boolean)");
402403
final static Method symintern = Method.getMethod("clojure.lang.Symbol intern(String, String)");
404+
final static Method internVar = Method.getMethod("clojure.lang.Var refer(clojure.lang.Symbol, clojure.lang.Var)");
403405

404-
public DefExpr(String source, int line, int column, Var var, Expr init, Expr meta, boolean initProvided, boolean isDynamic){
406+
public DefExpr(String source, int line, int column, Var var, Expr init, Expr meta, boolean initProvided, boolean isDynamic, boolean shadowsCoreMapping){
405407
this.source = source;
406408
this.line = line;
407409
this.column = column;
408410
this.var = var;
409411
this.init = init;
410412
this.meta = meta;
411413
this.isDynamic = isDynamic;
414+
this.shadowsCoreMapping = shadowsCoreMapping;
412415
this.initProvided = initProvided;
413416
}
414417

@@ -454,6 +457,18 @@ public Object eval() {
454457

455458
public void emit(C context, ObjExpr objx, GeneratorAdapter gen){
456459
objx.emitVar(gen, var);
460+
461+
if (shadowsCoreMapping)
462+
{
463+
gen.dup();
464+
gen.getField(VAR_TYPE, "ns", NS_TYPE);
465+
gen.swap();
466+
gen.dup();
467+
gen.getField(VAR_TYPE, "sym", SYMBOL_TYPE);
468+
gen.swap();
469+
gen.invokeVirtual(NS_TYPE, internVar);
470+
}
471+
457472
if(isDynamic)
458473
{
459474
gen.push(isDynamic);
@@ -511,11 +526,13 @@ else if(!(RT.second(form) instanceof Symbol))
511526
Var v = lookupVar(sym, true);
512527
if(v == null)
513528
throw Util.runtimeException("Can't refer to qualified var that doesn't exist");
529+
boolean shadowsCoreMapping = false;
514530
if(!v.ns.equals(currentNS()))
515531
{
516532
if(sym.ns == null)
517533
{
518534
v = currentNS().intern(sym);
535+
shadowsCoreMapping = true;
519536
registerVar(v);
520537
}
521538
// throw Util.runtimeException("Name conflict, can't def " + sym + " because namespace: " + currentNS().name +
@@ -559,7 +576,7 @@ else if(!(RT.second(form) instanceof Symbol))
559576
Expr meta = mm.count()==0 ? null:analyze(context == C.EVAL ? context : C.EXPRESSION, mm);
560577
return new DefExpr((String) SOURCE.deref(), lineDeref(), columnDeref(),
561578
v, analyze(context == C.EVAL ? context : C.EXPRESSION, RT.third(form), v.sym.name),
562-
meta, RT.count(form) == 3, isDynamic);
579+
meta, RT.count(form) == 3, isDynamic, shadowsCoreMapping);
563580
}
564581
}
565582
}

0 commit comments

Comments
 (0)