diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContext.java b/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContext.java index c0f7a7803..366f9422e 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContext.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/PredictionContext.java @@ -249,21 +249,30 @@ public abstract class PredictionContext implements Iterable b.invokingState ) { - payloads = new int[] {b.invokingState, a.invokingState}; + payloads[0] = b.invokingState; + payloads[1] = a.invokingState; } - PredictionContext[] parents = {parent, parent}; + PredictionContext[] parents = {singleParent, singleParent}; ArrayPredictionContext joined = new ArrayPredictionContext(parents, payloads); return joined; } - // parents differ, just pack together into array; can't merge. - // sort though by payload + // parents differ and can't merge them. Just pack together + // into array; can't merge. sort, though, by payload + // ax + by = [ax,by] int[] payloads = {a.invokingState, b.invokingState}; PredictionContext[] parents = {a.parent, b.parent}; if ( a.invokingState > b.invokingState ) { @@ -284,8 +293,8 @@ public abstract class PredictionContext implements Iterables1 [label=\"parent[0]\"];\n" + + " s5->s1 [label=\"parent[1]\"];\n" + + " s1->s0;\n" + + "}\n"; + assertEquals(expecting, PredictionContext.toDotString(r)); + } + + @Test public void test_a$_bx() { + PredictionContext x2 = createSingleton(PredictionContext.EMPTY, 9); + PredictionContext a = createSingleton(PredictionContext.EMPTY, 1); + PredictionContext b = createSingleton(x2, 2); + PredictionContext r = PredictionContext.merge(a, b, rootIsWildcard()); + System.out.println(PredictionContext.toDotString(r)); + String expecting = + "digraph G {\n" + + "rankdir=LR;\n" + + " s4 [shape=box, label=\"[1, 2]\"];\n" + + " s0 [label=\"$\"];\n" + + " s4->s0 [label=\"parent[0]\"];\n" + + " s4->s0 [label=\"parent[1]\"];\n" + + "}\n"; + assertEquals(expecting, PredictionContext.toDotString(r)); + } + @Test public void test_aex_bfx() { PredictionContext x1 = createSingleton(PredictionContext.EMPTY, 9); PredictionContext x2 = createSingleton(PredictionContext.EMPTY, 9);