In the old constraint-error, I was able to access properties (here, the type of a name) as follows:

module check

imports

  include/Entity
  lib/runtime/task/-
  lib/runtime/types/-
  names

rules
    
  constraint-error:
    Entity(x, _) -> (x, "Some error message")
    where
       type := <get-type> x // this succeeds!

When I change this to the task-based nabl-constraint, accessing a property fails:

module check

imports

  include/Entity
  lib/runtime/task/-
  lib/runtime/types/-
  names

rules

  nabl-constraint(|ctx):
     Entity(x, _) -> <fail>
     where
       type := <get-type> x; // this fails!
       <task-create-error(|ctx, "Some other message")> x

What am I doing wrong here?

Asked by Oskar van Rest on 20 September 2014 at 20:08

You need to use tasks in nabl-constraint.

Answered by Gabriël Konat on 20 September 2014 at 20:19

Right, I wasn’t thinking straight. Anyway, here some example for others, and for my own reference:

  module check
  
  imports
  
    include/Entity
    lib/runtime/task/-
    lib/runtime/nabl/-
    lib/runtime/properties/-
    names
  
  rules
    
    nabl-constraint(|ctx):
      Entity(x, properties) -> <fail>
      where
        prop-lookup-task := <prop-create-lookup(|ctx, NablProp_propA())> x;
        rewrite-task     := <task-create-rewrite(|ctx, "MyConstraint1")> (prop-lookup-task, properties, "hello");
        <task-create-error-on-failure(|ctx, rewrite-task, "Some error message")> x
        
    task-rewrite:
      ("MyConstraint1", (propA, properties, hello)) -> <id>
      where
        <debug> propA
        // implement your constraint checking here
Answered by Oskar van Rest on 20 September 2014 at 21:19