We thought we fixed this in https://github.com/antlr/antlr4/issues/195#issuecomment-268737026 but here's another case reported:
@ferhaterata says: provided a Grammar that ANTLR generates recognizer in 4.5.1 and 4.5.3 but fails in 4.6.1. The labels 'left' and 'right' represent two different types. Sorry for preparing a verbose grammar.
grammar Test;
module: formula* ;
formula:
left=expression 'in' right=expression #in
| left=formula 'and' right=formula #and
;
expression:
left=expression '+' right=expression #union
| variable #var
;
variable: IDENTIFIER;
IDENTIFIER : [a-zA-Z];
It throws
error(75): Test.g4:2:13: label left=expression type mismatch with previous definition: left=formula
error(75): Test.g4:5:57: label right=formula type mismatch with previous definition: right=expression
In fact, this one works fine,
grammar test1;
example:
left=integer '*' right=integer #integerExample
| left=string '+' right=string #stringExample
;
integer: IDENTIFIER;
string: INTEGER;
STRING: [a-zA-Z];
INTEGER: [a-zA-Z];
I assume the problem occurs once repetitions are allowed in labels.
I'm working on this one today.
@KvanTTT I fixed the regression by disabling this analysis for left-recursive rules altogether. I'm leaving this issue open, and you'll find a unit test with @Ignore which I added in #1570. After analysis is working for these rules the test can be enabled and this issue will be fully resolved.
Most helpful comment
I'm working on this one today.