Skip to content
  • HELP
  • ERROR MESSAGES
  • SHADOWED_VARIABLE

Error code: SHADOWED_VARIABLE

This guide explains why you may experience a shadowed variable error and how to solve it.

In Rel, all variables have to be explicitly introduced to clarify their scope. Moreover, they are introduced by bindings. For instance, a local scalar variable x shadows relation definitions, schema, and natives with name x.

Consider the following example that returns an error:

def names = {"Patrick"; "Joe"}
def dbl_names(n, n) = names(n)
Error example from the RAI Console

In the query above, you defined the relation dbl_names with the purpose of doubling the elements of the tuples in the relation names. In this case, you have used the same variable name, i.e., n, in the binding for the relation dbl_names. This returns the shadowed variable error.

To solve this, you have to use a different name for every variable in a certain enclosing scope. For example:

// query
 
def names = {"Patrick"; "Joe"}
def dbl_names(x, y) = {names(x) and names(y)}
def output = dbl_names
Was this doc helpful?