Ideal IMO would be a compile time error, since getLikes() returns a Cheese instance, but as we use MVEL to resolve the expression, I'm not 100% sure we are able to cover all possible scenarios at compile time. I guess we can, but need to double check that.

   []s
   Edson

2007/9/27, Chris Woodrow <woodrow.chris@gmail.com>:
Thanks.
I was supposing so...
Do you think test 3 should throw a ClassCastException or just not match?
Chris

2007/9/27, Edson Tirelli < tirelli@post.com >:

   Yes, drools is deferring the type verification until it is needed (in your example, to check the constraint). May I ask you please to open a JIRA... I will fix that.

  []s
  Edson

2007/9/27, Chris Woodrow <woodrow.chris@gmail.com>:
I am sorry I didn't mean 'for' but 'from'.
:D

2007/9/27, Chris Woodrow < woodrow.chris@gmail.com>:
Hi,
I recently find out a few issues using for, and I wanted to share it with you. I made a simple exemple to illustrate my purpose.

My classes are (I did not represent accessors & constructors):

public class Cheese {
    protected String name;
}

public class FrenchCheese extends Cheese{
    private String smell;
}

public class Person {
    private Cheese likes;
}

Here is my rule set :

package rules

rule "likes cheese"
    when
        $person : Person ()
        Cheese(  ) from $person.getLikes()
    then
        System.out.println ("likes cheese");
end


rule "likes french cheese"
    when
        $person : Person ()
        FrenchCheese(  ) from $person.getLikes()
    then
        System.out.println ("likes french cheese");
end

First test :
        Cheese cheese = new FrenchCheese("good", "camembert");
        Person person = new Person();
        person.setLikes(cheese);

Output :
likes french cheese
likes cheese

Wich is expected...

Second test :
        Cheese cheese = new Cheese();
        Person person = new Person();
        person.setLikes(cheese);

Output :
likes french cheese
likes cheese

That's the first strange thing. As far as I am concerned, rule "likes french cheese" should not match (since a Cheese is not a FrenchCheese).

I made a change to the second rule :
rule "likes french cheese"
    when
        $person : Person ()
        FrenchCheese( smell == "good" ) from $person.getLikes()
    then
        System.out.println("likes french cheese");
end

Third test :
        Cheese cheese = new Cheese();
        Person person = new Person();
        person.setLikes(cheese);

output :
It throwed an exception : Exception in thread "main" java.lang.ClassCastException: rules.Cheese
I am not saying the ClassCastException is not to expect in such a case but I think I would simply expect it not to match (as far as a Cheese is not a FrenchCheese).

Chris


_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users




--
  Edson Tirelli
  Software Engineer - JBoss Rules Core Developer
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users




--
  Edson Tirelli
  Software Engineer - JBoss Rules Core Developer
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com