From 4e4b902c204697755a049f795519dae360b61d72 Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Wed, 7 Dec 2016 22:40:07 +0300 Subject: [PATCH] Added test testLabelsForTokensWithMixedTypes. --- .../antlr/v4/test/tool/TestSymbolIssues.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/TestSymbolIssues.java b/tool-testsuite/test/org/antlr/v4/test/tool/TestSymbolIssues.java index f30d9c1c4..a964231b3 100644 --- a/tool-testsuite/test/org/antlr/v4/test/tool/TestSymbolIssues.java +++ b/tool-testsuite/test/org/antlr/v4/test/tool/TestSymbolIssues.java @@ -309,4 +309,39 @@ public class TestSymbolIssues extends BaseJavaToolTest { testErrors(test, false); } + + // https://github.com/antlr/antlr4/issues/1409 + @Test public void testLabelsForTokensWithMixedTypes() { + String[] test = { + "grammar L;\n" + + "\n" + + "rule1 // Correct (Alternatives)\n" + + " : t1 = a #aLabel\n" + + " | t1 = b #bLabel\n" + + " ;\n" + + "rule2 //Incorrect type casting in generated code (RULE_LABEL)\n" + + " : t2 = a | t2 = b\n" + + " ;\n" + + "rule3\n" + + " : t3 += a+ b t3 += c+ //Incorrect type casting in generated code (RULE_LIST_LABEL)\n" + + " ;\n" + + "rule4\n" + + " : a t4 = A b t4 = B c // Correct (TOKEN_LABEL)\n" + + " ;\n" + + "rule5\n" + + " : a t5 += A b t5 += B c // Correct (TOKEN_LIST_LABEL)\n" + + " ;\n" + + "a: A;\n" + + "b: B;\n" + + "c: C;\n" + + "A: 'a';\n" + + "B: 'b';\n" + + "C: 'c';\n", + + "error(" + ErrorType.LABEL_TYPE_CONFLICT.code + "): L.g4:8:15: label t2=b type mismatch with previous definition: t2=a\n" + + "error(" + ErrorType.LABEL_TYPE_CONFLICT.code + "): L.g4:11:17: label t3+=c type mismatch with previous definition: t3+=a\n" + }; + + testErrors(test, false); + } }