Subject: [26.0.91 9] optimistic forward-sexp

From: Andreas Röhler <[email-masked]>
Date: Tue, 6 Mar 2018 08:16:47 +0100

In GNU Emacs 26.0.91 (build 1, i686-pc-linux-gnu, GTK+ Version 3.14.5)
  of 2018-01-27

 From 
https://emacs.stackexchange.com/questions/39253/sh-mode-scan-error-containing-expression-ends-prematurely

Error occurs when forward-sexp is called from closing paren at last line 
of example code below

(echo '#!/bin/bash'
echo 'myfunc() {'
echo "cat <<'z'"
seq 135
echo zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
echo z
echo '}') >out

Bug-source is in but-last line of the def in lisp.el, where

     (goto-char (or (scan-sexps (point) arg) (buffer-end arg)))

scan-sexps sends the error.

Wrapping in into (ignore-errors...

(or (ignore-errors (scan-sexps (point) arg))

makes it gone.

Cheers,

Andreas