Revert "Revert r178079, it caused PR15637."

This reverts commit r178497 since the backend has been fixed.

Also add a test to ensure that we're emitting template information for unions.