Fix some type-checking issues when compiling database predicate calls and messages