Fix handling of struct variants in a couple of places

Fixes #17405.
Fixes #17518.
Fixes #17800.