fix a silly bug in the intrinsic code and add a testcase that would have...

... caught it