Better check for instance equality of generic types. Fixes #15100