Thank you for your elaboration,
it makes the issue a lot clearer to me. So I replaced
set the_result_2 to path of the_doc
with
set the_result_2 to «property ppth» of the_doc
and now the AS script text can be run with osascript without throwing an error.
I think, the whole story shows a flaw in Apple Script: The compiler should not do guessing if the code is ambiguous and should throw a compilation error instead.