@dvyukov Some comments are attached, some are not. In general, the AST support for comments is not ideal. Comments inside functions are not attached at all. There's complex code in the printer that merges comments and code by comparing position information.
I haven't looked at the specifics of this problem. A generally correct solution (for all comments) is very difficult with the current AST. Maintaining function (and general declaration comments) should be doable. There's also the ast.CommentMap which may work for this problem.
The long-term solution is a new AST where all comments are attached to nodes.