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) 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
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:
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.
declare enumcannot reference another declared enum constant as a field type / constructor argSummary
A DRL
declare enumcannot 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 toStringlookup codes throughout cross-referenced enum sets, losing type safety.Historical context
The limitation has existed since the
declare enumfeature was introduced. JBRULES-3009 commitba47bd6(2012-01-17) added the feature and added the canonical test fixturetest_Enums.drlwith 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
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:The commented-out lines are exactly the case that should work — strongly suggesting the limitation is known.