Uploaded image for project: 'JBRULES'
  1. JBRULES
  2. JBRULES-2836

Nested conditional expression (x?y:z) does not resolve variable binding

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more

XMLWordPrintable

    • Hide

      declare One
      attr1 : Integer
      attr2 : Integer
      end

      declare Two
      sum : int
      end

      rule "launcher"
      when
      then
      insert( new One( 42, null ) );
      insert( new Two( 1 ) );
      end

      rule "check sum"
      when
      One( $a1: attr1, $a2: attr2 )
      Two( sum == ( $a1 != null ? ( $a2 != null ? 2 : 1 ) : 0 ) )

      1. Two( sum == ( ( $a1 != null ? 1 : 0) + ( $a2 != null ? 1 : 0 ) ) ) // This works.
        then
        System.out.println( "MATCH" );
        end
      Show
      declare One attr1 : Integer attr2 : Integer end declare Two sum : int end rule "launcher" when then insert( new One( 42, null ) ); insert( new Two( 1 ) ); end rule "check sum" when One( $a1: attr1, $a2: attr2 ) Two( sum == ( $a1 != null ? ( $a2 != null ? 2 : 1 ) : 0 ) ) Two( sum == ( ( $a1 != null ? 1 : 0) + ( $a2 != null ? 1 : 0 ) ) ) // This works. then System.out.println( "MATCH" ); end

      A return value restriction containing a nested conditional expression referencing two previously bound variables is flagged as erroneous. (A similar, not nested, expression referencing the same variables, is compiled and executed correctly.)

      The provided DRL is sufficient for producing the error:

      ule Compilation error : [Rule name='check sum']
      appl/domain/Rule_check_sum_0.java (9:417) : $a2 cannot be resolved

            etirelli@redhat.com Edson Tirelli
            laune Wolfgang Laun (Inactive)
            Archiver:
            rhn-support-ceverson Clark Everson

              Created:
              Updated:
              Resolved:
              Archived: