Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type mismatch between left and right labels in left-recursive rule #1543

Closed
parrt opened this issue Dec 22, 2016 · 2 comments · Fixed by #1585
Closed

type mismatch between left and right labels in left-recursive rule #1543

parrt opened this issue Dec 22, 2016 · 2 comments · Fixed by #1585

Comments

@parrt
Copy link
Member

parrt commented Dec 22, 2016

We thought we fixed this in #195 (comment) 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.

@sharwell
Copy link
Member

sharwell commented Jan 2, 2017

I'm working on this one today.

@sharwell
Copy link
Member

sharwell commented Jan 4, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants