drccrd opened a new issue, #6737:
URL: https://github.com/apache/incubator-kie-drools/issues/6737

   # `declare enum` cannot reference another declared enum constant as a field 
type / constructor arg
   
   ## Summary
   
   A DRL `declare enum` cannot use another declared enum as the type of one of 
its fields, and cannot use an enum literal (e.g. `Foo.BAR`) as a constructor 
argument. Both the legacy DRL compile path and the executable-model path fail, 
in different ways. This forces users to fall back to `String` lookup codes 
throughout cross-referenced enum sets, losing type safety.
   
   ## Historical context
   
   The limitation has existed since the `declare enum` feature was introduced. 
[JBRULES-3009 commit `ba47bd6` 
(2012-01-17)](https://github.com/apache/incubator-kie-drools/commit/ba47bd6#diff-a609279314f8f74901966f88eb7968891e41fdf5a0defc6a9ca456029dced6ea)
 added the feature *and* added the canonical test fixture `test_Enums.drl` with 
the cross-enum case **already commented out** — the original author possibly 
intended this to work, wrote the test for it, then commented it out before 
merging. The lines have sat untouched for ~14 years.
   
   ## Reproduction
   
   ```drl
   package org.example;
   
   declare enum Categories
     Target("target"),
     NonTarget("non-target"),
     NewLesion("new");
   
     code: String;
   end
   
   declare enum LesionStates
     TargetNotAssessed( org.example.Categories.Target, "notassessed" ),
     TargetPresent(     org.example.Categories.Target, "present"     );
   
     category: org.example.Categories;
     nominalAnswerType: String;
   end
   ```
   
   Compiling this DRL fails. The same shape appears commented-out in the 
canonical test fixture:
   
   
[`drools-test-coverage/test-compiler-integration/src/test/resources/org/drools/mvel/integrationtests/test_Enums.drl#L46-L54`](https://github.com/apache/incubator-kie-drools/blob/main/drools-test-coverage/test-compiler-integration/src/test/resources/org/drools/mvel/integrationtests/test_Enums.drl#L46-L54):
   
   ```drl
   declare enum WorkLoad
   //    LIGHT( x.DaysOfWeek.TUESDAY, 4 ),
   //    MEDIUM( x.DaysOfWeek.MONDAY, 8 ),
   //    HEAVY( x.DaysOfWeek.SUNDAY, 12 );
   
       LIGHT( 4 ), MEDIUM( 8 ), HEAVY( 12 );
   
   //    day     : DaysOfWeek
       hours   : int
   end
   ```
   
   The commented-out lines are exactly the case that should work — strongly 
suggesting the limitation is known.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to