Formatting error with source code on WordPress.com?

Paste the code in the HTML editor, it probably won’t try to convert indents and linebreaks. Surround it with the [sourcecode] shortcode and only then return to the visual editor.