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

[new-parser] rule super_key failed predicate #5703

Closed
yurloc opened this issue Feb 20, 2024 · 1 comment
Closed

[new-parser] rule super_key failed predicate #5703

yurloc opened this issue Feb 20, 2024 · 1 comment

Comments

@yurloc
Copy link
Contributor

yurloc commented Feb 20, 2024

Parent issue

Failing tests

  • org.drools.model.codegen.execmodel.NodeSharingTest#testShareAccumulate

Notes

  • STANDARD_FROM_DRL only.

Rule code snippet

  accumulate ( $p: Person ( getName().startsWith(\"M\") );
                $sum : sum($p.getAge())
              )

Error output

### parse : ANTLR4_PARSER_ENABLED = true
line 1:10 rule super_key failed predicate: {(helper.validateIdentifierKey(DroolsSoftKeywords.SUPER))}?
line 1:10 rule super_key failed predicate: {(helper.validateIdentifierKey(DroolsSoftKeywords.SUPER))}?
21:44:44.693 [main] ERROR o.d.c.k.b.impl.AbstractKieProject.buildKnowledgePackages:280 - Unable to build KieBaseModel:defaultKieBase
Unable to Analyse Expression getName().:
Index 10 out of bounds for length 10 : [Rule name='X1']



java.lang.AssertionError: [Message [id=1, kieBase=defaultKieBase, level=ERROR, path=r0.drl, line=-1, column=0
   text=Unable to Analyse Expression getName().:
Index 10 out of bounds for length 10]]

	at org.drools.model.codegen.execmodel.BaseModelTest.createKieBuilder(BaseModelTest.java:157)
	at org.drools.model.codegen.execmodel.BaseModelTest.createKieBuilder(BaseModelTest.java:132)
	at org.drools.model.codegen.execmodel.BaseModelTest.getKieContainer(BaseModelTest.java:121)
	at org.drools.model.codegen.execmodel.BaseModelTest.getKieContainer(BaseModelTest.java:114)
	at org.drools.model.codegen.execmodel.BaseModelTest.getKieSession(BaseModelTest.java:110)
	at org.drools.model.codegen.execmodel.BaseModelTest.getKieSession(BaseModelTest.java:106)
	at org.drools.model.codegen.execmodel.NodeSharingTest.testShareAccumulate(NodeSharingTest.java:345)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
	at java.base/java.lang.reflect.Method.invoke(Method.java:577)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runners.Suite.runChild(Suite.java:128)
	at org.junit.runners.Suite.runChild(Suite.java:27)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
	at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:42)
	at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:80)
	at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:72)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:147)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:127)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:90)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:55)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:102)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:54)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
	at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
	at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:57)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
	at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:232)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55)
@yurloc
Copy link
Contributor Author

yurloc commented Feb 26, 2024

@tkobayas I'm taking this one.

yurloc added a commit to yurloc/drools that referenced this issue Feb 27, 2024
This is how one of the `selector` subrules looks like in the old parser:

   (DOT super_key)=>DOT { helper.emit($DOT, DroolsEditorType.SYMBOL); } super_key superSuffix

The whole rule is guarded by a syntactic predicate that is used to make
the decision whether this alternative is viable.

Syntactic predicates were removed in ANTLR 4 so this subrule became:

    DOT { helper.emit($DOT, DroolsEditorType.SYMBOL); } super_key superSuffix

The failing predicate is "hidden" inside the `super_key` rule but it actually
cannot be used to make the decision because it is now "invisible". See
https://github.com/antlr/antlr4/blob/master/doc/predicates.md#finding-visible-predicates
that explains how predicates can become invisible. The thing that makes
the predicate invisible here is the action after `DOT`. And since the
alternative is now unguarded it seems viable and so it is taken and
the `super_key` rule is evaluated.

At this point, inside `super_key` there is only a single alternative. It
is guarded by a predicate that evaluates to `false`, which is an error
condition.

The fix is to restore the guard in front of this `selector` alternative
that prevents taking should the super key predicate later turn out to be
false.

Fixes apache#5703.
yurloc added a commit to yurloc/drools that referenced this issue Feb 27, 2024
This is how one of the `selector` subrules looks like in the old parser:

    (DOT super_key)=>DOT { helper.emit($DOT, DroolsEditorType.SYMBOL); } super_key superSuffix

The whole rule is guarded by a syntactic predicate that is used to make
the decision whether this alternative is viable.

Syntactic predicates were removed in ANTLR 4 so this subrule became:

    DOT { helper.emit($DOT, DroolsEditorType.SYMBOL); } super_key superSuffix

The failing predicate is "hidden" inside the `super_key` rule but it actually
cannot be used to make the decision because it is now "invisible". See
https://github.com/antlr/antlr4/blob/master/doc/predicates.md#finding-visible-predicates
that explains how predicates can become invisible. The thing that makes
the predicate invisible here is the action after `DOT`. And since the
alternative is now unguarded it seems viable and so it is taken and
the `super_key` rule is evaluated.

At this point, inside `super_key` there is only a single alternative. It
is guarded by a predicate that evaluates to `false`, which is an error
condition.

The fix is to restore the guard in front of this `selector` alternative
that prevents taking should the super key predicate later turn out to be
false.

Fixes apache#5703.
@yurloc yurloc closed this as completed Mar 4, 2024
@github-project-automation github-project-automation bot moved this from 📋 Backlog to 🎯 Done in 🦉 KIE Podling Board Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

1 participant