Newtype structs as immediates

Fix #6612. Rebase of #6725. Fixed an additional bug and added a test.