In trying to theme a textfield element, I noticed that while my theme was being invoked at
$content = theme($elements['#theme'], $elements);
but the standard output from theme_textfield was reaching the browser.
form_render invokes the theme, but as $elements['#printed'] hasn't been set, form_render then invokes the standard theme for the element type
if (!isset($elements['#printed'])) {
$content = theme(($elements['#type']) ? $elements['#type']: 'markup', $elements);
$elements['#printed'] = TRUE;
}
Adding $element['#printed'] = TRUE after the element is themed seems unpredictable: if $elements['type'] is form, then the form element does not get rendered. I've special-cased that, and pages appear to be working (and looking at theme_form it's obvious why) but this seems strange.
I was about to file this as a bug, but decided to check if I am misunderstanding how element themeing is supposed to function. The Forms API Reference is ... vague ... on the matter. I could see having to set #printed in the theme function, but the way themes are invoked makes this impossible.