Holomorphic 1-forms in $y^2-(z-a_1)\ldots(z-a_n)$

I know that the surface $y^2-(z-a_1)\ldots(z-a_n)$ is a Riemann Surface (that is the Riemann surface of $\sqrt{P(z)}$ with $P(z)=(z-a_1)\ldots(z-a_n)$) of genus $g$ and that $g=\mathrm{dim}(\Omega(X))$, with $\Omega(X)$ the holomorphics 1-forms. In "Lectures on Riemann Surfaces" (17.15), Forster says that one has the basis $(\omega_j)_{j=1,\ldots,g}$ where $\omega_j=\frac{z^{j-1}dz}{\sqrt{P(z)}}$.

My problem is that when I prove the independence of this sequence I didn't use that the indices stopped at $g$ that is I had an infinite basis: if we have $\sum_j \lambda_j\omega_j=0$ then $\sum_j \lambda_j z^{j-1}=0$ and so with a Vandermonde determinant I conclude that the $\lambda_j=0$.

Where is my mistake?

-

You overlook the fact that from $j > g$, $\omega_j$ is no longer holomorphic, particularly at the point(s) with $z = \infty$ :
Suppose $n$ is even so that the surface has two points above $z = \infty$ (corresponding to $y = \pm z^{n/2}$). Then $g = n/2-1$. Pick $q = 1/z$. $q$ is a uniformizer at those two points, and $dq = -dz/z^2$. So $\omega_j / dq = - z^{j+1}/y = \pm z^{j+1-n/2} = \pm q^{-j-1+n/2}$. This has a pole at $z = \infty$ if and only if $-j-1+n/2 < 0$, which means $j > n/2-1 = g$.
If $n$ is odd, $g = (n+1)/2-1$, and there is a branch point at $z = \infty$. A uniformizer is now $q = y /z^{(n+1)/2} \sim 1/\sqrt z$. Then $z \sim q^{-2}$ has a pole of order $2$, $y \sim q^{-n}$ has a pole of order $n$, $dq/dz \sim z^{-3/2} \sim q^3$ has a zero of order $3$, and $\omega_j/dq = (z^{j-1}/y) (dz/dq) \sim q^{-2(j-1)+n-3} = q^{-2j+n-1}$. This has a pole if and only if $-2j+n-1 < 0$, which means $j > (n-1)/2 = g$.