From 294948cf49f03ed194d961190c6601a25678659b Mon Sep 17 00:00:00 2001 From: Gene Gleyzer Date: Tue, 12 Sep 2023 09:05:11 -0400 Subject: [PATCH] Fix a compiler assertion --- .../org/xvm/compiler/ast/NewExpression.java | 11 ++++ manualTests/src/main/x/TestSimple.x | 54 +++++++------------ 2 files changed, 30 insertions(+), 35 deletions(-) diff --git a/javatools/src/main/java/org/xvm/compiler/ast/NewExpression.java b/javatools/src/main/java/org/xvm/compiler/ast/NewExpression.java index 22937f02fe..357a585b89 100644 --- a/javatools/src/main/java/org/xvm/compiler/ast/NewExpression.java +++ b/javatools/src/main/java/org/xvm/compiler/ast/NewExpression.java @@ -823,6 +823,17 @@ else if (fNestMate && typeTarget.isVirtualChild() || typeTarget.isInnerChildClas m_mapRegisters = ctxAnon.ensureRegisterMap(); m_fInstanceChild = ctxAnon.isInstanceChild(); m_ctxCapture = null; + + // make sure the capture names don't collide + ClassStructure clzAnon = ctxAnon.getThisClass(); + for (String sName : m_mapCapture.keySet()) + { + if (clzAnon.getChild(sName) != null) + { + log(errs, Severity.ERROR, Compiler.NAME_COLLISION, sName); + return null; + } + } } m_plan = plan; diff --git a/manualTests/src/main/x/TestSimple.x b/manualTests/src/main/x/TestSimple.x index 85b6afcc32..ff68b5daaa 100644 --- a/manualTests/src/main/x/TestSimple.x +++ b/manualTests/src/main/x/TestSimple.x @@ -1,40 +1,24 @@ - module TestSimple { - @Inject Console console; +module TestSimple { + @Inject Console console; - void run() { - Callback[] callbacks = new Array(); - callbacks.add(new MyCallbackOne()); - callbacks.add(new MyCallbackTwo()); + void run() { + } - // the line below used to throw TypeMismatch at run-time; it no longer compiles - // Callback[] filtered = callbacks.filter(c -> !c.is(MyCallbackOne)); - Collection filtered = callbacks.filter(c -> !c.is(MyCallbackOne)); - for (Callback callback : filtered) { - callback.call(); - } - - for (Callback callback : callbacks.filter(c -> c.is(MyCallbackOne))) { - callback.call(); - } - } - - interface Callback { - void call(); - } - - const MyCallbackOne - implements Callback { - @Override - void call() { - console.print("one"); - } - } + Iterator test(Int next) { // the name collision used to assert the compiler + return new Iterator() { + private Int nextValue = next; + private Boolean hasNext = True; - const MyCallbackTwo - implements Callback { @Override - void call() { - console.print("two"); + conditional Element next() { + if (hasNext) { + Int value = nextValue; + hasNext = False; + return True, value; + } else { + return False; + } } - } - } \ No newline at end of file + }; + } +} \ No newline at end of file