improved object declaration error messages (closes #1867)