Add helpful error message when trying to re-parent an existing AST node.
This turns a completely unhelpful error into something which is hopefully very obvious.
@@ -729,7 +729,10 @@ public class Node implements Serializable {
}
public void addChildToBack(Node child) {
- checkArgument(child.parent == null);
+ checkArgument(
+ child.parent == null,
+ "Cannot add already-owned child node.\nChild: %s\nExisting parent: %s\nNew parent: %s",
+ child, parent, this);
checkArgument(child.next == null);
checkArgument(child.previous == null);
