Skip to content

Null pointer in named alternative with attributes #855

@oldwo

Description

@oldwo

Probably the same as #822 , this one is stopping my work.

grammar probz;
statement
locals[Scope scope]
    : expressionA[$scope] ';'
    ;
expressionA[Scope scope]
    : atom[$scope]
    | expressionA[$scope] '[' expressionA[$scope] ']'
    ;
atom[Scope scope]
    : 'dummy'
    ;

Which throws an exception upon compilation:
C:\ANTLRprobz>java -jar antlr4-4.5.1-complete.jar probz.g4
new Rule() name=T__0 ast=RULE
new Rule() name=T__1 ast=RULE
new Rule() name=T__2 ast=RULE
new Rule() name=T__3 ast=RULE
getAltLabels() index=0 numberOfAlts=1 name=T__0 alt[i1].Num1.ast=ALT=>true
getAltLabels() index=1 numberOfAlts=1 name=T__1 alt[i1].Num1.ast=ALT=>true
getAltLabels() index=2 numberOfAlts=1 name=T__2 alt[i1].Num1.ast=ALT=>true
getAltLabels() index=3 numberOfAlts=1 name=T__3 alt[i1].Num1.ast=ALT=>true
new Rule() name=statement ast=RULE
new Rule() name=expressionA ast=RULE
new Rule() name=atom ast=RULE
getAltLabels() index=0 numberOfAlts=1 name=statement alt[i1].Num1.ast=ALT=>true
getAltLabels() index=1 numberOfAlts=1 name=expressionA alt[i1].Num1.ast=ALT=>true
getAltLabels() index=1 numberOfAlts=1 name=expressionA alt[i1].Num1.ast=ALT=>true
getAltLabels() index=2 numberOfAlts=1 name=atom alt[i1].Num1.ast=null=>true
context [/report INTERNAL_ERROR] 1:17 attribute arg isn't defined
error(20): internal error:
Exception in thread "main" java.lang.NullPointerException
at org.antlr.v4.semantics.SemanticPipeline.process(SemanticPipeline.java:116)
at org.antlr.v4.Tool.processNonCombinedGrammar(Tool.java:399)
at org.antlr.v4.Tool.process(Tool.java:386)
at org.antlr.v4.Tool.processGrammarsOnCommandLine(Tool.java:345)
at org.antlr.v4.Tool.main(Tool.java:192)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions