Fix second-order matching to properly check that the predicate found by
abstraction has the right type. Fixes bug# 3306.
Add test-suite files for bugs 3305 and 3306.