Can two analytic functions that agree on the boundary of a domain, each from a different direction, can be extending into one function?

Let $D=\{z:|z|\leq 1\}$ be the unit disc in $\mathbb{C}$.
Say $f$ is analytic on $D$ and $g$ is analytic on $\overline{D^c}$, and that $f|_{\partial D}=g|_{\partial D}$.

Is there necessarily an analytic function $h$ such that $h|_D=f$ and $h|_{D^c}=g$?

Solutions Collecting From Web of "Can two analytic functions that agree on the boundary of a domain, each from a different direction, can be extending into one function?"

Define
$$
h(z) = \begin{cases} f(z), & |z|\le 1 \\ g(z), & |z| > 1. \end{cases}
$$
By assumption, $h$ is continous on $\mathbb{C}$, so by Morera’s theorem, it suffices to check whether
$$
\int_\gamma h(z)\,dz = 0
$$
for all closed curves $\gamma$. In fact, it is enough to check that the integral vanishes for all triangles.

Let $\gamma$ be an arbitrary triangle. There are a few cases to consider. If $\gamma$ encloses the unit disc, it follows by deformation of contours that
$$
\int_\gamma h(z)\,dz = \int_{|z| = 1} h(z)\,dz = \int_{|z| = 1} f(z)\,dz = 0
$$
by Cauchy’s integral theorem. Similarly, if $\gamma$ is in the interior of the unit disc, the integral vanishes again by Cauchy’s integral theorem.

Finally, if the triangle intersects the unit circle, we can write the triangle as the union of a number of curves lying completely inside or completely outside the unit disc. These curves consist of line segments that together form the original triangle together with arcs along the circle traversed twice; once in each direction. All in all, the integral along each such closed curve vanishes, yet again by Cauchy’s integral theorem, so our $h$ is indeed an entire function.

Note: we need a version of Cauchy’s integral theorem valid for functions holomorphic on (or outside) the unit disc, continous up to the boundary. Not all textbooks prove this version, but it’s fairly straight-forward.