AttachToEntity

io.getquill.norm.AttachToEntity

Find the innermost clause that contains an entity and attach some other kind of clause into it, e.g. a Filter. For example if you have an AST that looks like this:

 FlatMap(Map(Entity(A), a, B), b, C)

Then AttachToEntity(Filter(_, _, Cond) will result in this:

 FlatMap(Map(Filter(Entity(A), {tmp}, Cond), a, B), b, C)

Note how the inner ident {tmp} needs to be unique and not conflict with any ident higher in the AST that is used inside the Cond clause, otherwise, the various kinds of ASTs will be irreversibly corrupted. Here is an example:

Take:

 FlatMap(A, a, Entity(C))

Attached to the clause:

 Filter(_, {dangerous_tmp}, If(a == x, foo, bar))

Which results in:

 FlatMap(A, a, Filter(Entity(C), {dangerous_tmp}, If(a == x, foo, bar))

If {dangerous_tmp} is the Ident 'a' then the following happens: (I have added curly braces {} around this Ident just to distinguish it)

 FlatMap(A, a, Filter(Entity(C), {a}, If(b == x, foo, bar))

At that point the 'a' inside the attached Filter and the outside FlatMap are indistinguishable and indeed, the next phase of AvoidAliasConflict will likely turn this expression into the following:

 FlatMap(A, a, Filter(Entity(C), {a1}, If(a1 == x, foo, bar))

This is of course completely incorrect because the ident {a1} should actually be {a} referring to the ident of the outer FlatMap.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Concrete methods

def apply(f: (Ast, Ident) => Query, alias: Option[Ident])(q: Ast): Ast