fix assignment of optionals, adds a unit test

cc: @artemp @kkaefer @springmeyer