Fix bug where pattern-matching treats a type parameter as if it is a reference (which it might not be) Fixes #35584