The following is one version of Morera's theorem from complex analysis, as presented by Theodore W. Gamelin.
Theorem (Morera’s Theorem).
Let $f(z)$ be a continuous function on a domain $D$ (defined as simple connected open set). If
\begin{equation*} \int_{\partial R} f(z)\,dz = 0 \end{equation*} for every closed rectangle $R \subset D$ with sides parallel to the coordinate axes, then $f(z)$ is analytic on $D$.
Since continuity can be extended to the boundary of $D$ and we may still define the function, \begin{equation*} F(z) = \int_{z_0}^{z} f(\zeta) \, d\zeta, \quad z \in \bar{D}, \end{equation*} where $z_{0}$ is a fixed point in $D$, and the path of integration runs along a horizontal line and then a vertical line, whenever such a path is contained in $\bar{D}$. Now we can then attempt to differentiate $F(z)$. Indeed,
\begin{equation*} F(z + \Delta z) - F(z) = \int_{z}^{\,z+\Delta z} f(\zeta) \, d\zeta, \end{equation*} If $z$ lies on the boundary of $D$, then $\Delta z$ must be restricted to directions for which the segment $[z, z+\Delta z]$ is contained in $\bar{D}$.
Here arises my puzzle: the difference quotient
\begin{equation*} \frac{F(z+\Delta z) - F(z)}{\Delta z} \end{equation*} appears to exist even when $z$ is on the boundary of $D$. Since $f$ is continuous at $z$, this suggests that $F$ is analytic on $\bar{D}$, and therefore so is $f$. However, we know that analytic functions are defined only on open sets. Which step in this reasoning is mistaken?