one irrelevant question though, it looks like most of the calls to ResultBuilder::setPreferredType performs a !isNull check before hand. should we perform this check implicitly and make the setPreferredType no-op in case of a null type?
I don't see any reason why not, that could save some typing.
Better yet, we might be able to remove it altogether. Preferred type is also stored in completion context and I'm not sure whether it's ever different from the one in ResultBuilder.