Make the diagnostic for static variables in patterns better

Fixes #17933.