Why to put ".copy" to a type in a typesystem concept
Seen the subject in many places. So why should we copy a type node while using :==: in a typesystem concept?
Please sign in to leave a comment.
A quotation is an easy way to instantiate a node and defining properties, childs and references. When you reference an existing node inside an antiquotation and don't create a copy, this node is set as a child of the newly created node and because every node can only have one parent, it is removed from its previous parent.
In this case the copy is not related to the typesystem equation.
More information about quotations http://confluence.jetbrains.net/display/MPSD25/Typesystem#Typesystem-Quotations
So, the rule is: when you use a type you got from typesystem (using node.type operation), you should .copy it as soon as possible, especially if you are going to $COPY_SRC$ it in the generator, or to insert it into another model (inserting node somewhere detaches it from the original location).
If someone defines typeof(VarRef) :==: node.varDecl.type; and another guy writes an extract variable intention, most probably the original varDecl.type might disappear after the intention... That's why you see node.varDecl.type.copy.