This doesn't add a test for the main problem in #8640 since it seems that was already fixed (including a test) in PR #19522. This just adds a test for a program mentioned in the comments that used to erroneously compile. Closes #8640.