After a few clarifying comments I'll go back to rewrite from scratch my answer.
Mechanical work $W_{AB;\gamma}$ from a point $A$ to a point $B$ along a curve $\gamma$ of parametric representation ${\bf s}(\alpha)$, where $\alpha_A \leq \alpha \leq \alpha_B$ and ${\bf s}(\alpha_A)= {\bf r_A}$, is the position vector of $A$ and ${\bf s}(\alpha_B)= {\bf r_B}$ is the position vector of $B$, is the integral of a differential form:
$$
W_{AB;\gamma}= \int_{A;\gamma}^B{\bf F}({\bf r}) \cdot d{\bf s}=\int_{\alpha_A}^{\alpha_B}{\bf F}({\bf s}(\alpha))\cdot\frac{d{\bf s}}{d \alpha}d \alpha~~~~~~~~~~~[1]
$$
Where $ {\bf F}({\bf r})$ is the total force at point ${\bf r}$ and $d{\bf s}$ represents an infinitesimal displacement tangent to $\gamma$ at the same point.
As integral of a differential form (if one likes the exterior algebra point of view, as integral of a $1$-form) $[1]$ is in general path dependent. Which means that for a given pair points $A$ and $B$ $W_{AB;\gamma}$ will depend on the curve $\gamma$ chosen to join them. In such (generic) case, one says that the form ${\bf F}\cdot d{\bf s}$ in non-integrable or non-exact.
In some special cases it happens that there exists a scalar function ($0$-form) $V({\bf r})$ such that ${\bf F}= -\nabla V$ and in such a case it is possible to show that $W_{AB;\gamma}$ does not depend on the path $\gamma$ anymore, but depends only on the initial and final points, through the values of $V$ at those points:
$$
W_{AB;\gamma}= W_{AB}= V({\bf r}_B) - V({\bf r}_A).
$$
This is the case of th so-calld exact forms or integrable forms.
So far, there is no ambiguity in the notation.
Problems can come if one uses without care the mathematical notation for the differential forms (not their integrals).
Mathematical notation is actually coherent. A differential form (exact o non-exact) is indicated using Leibnitz's d notation. For instance $dW={\bf F}\cdot d{\bf s}$. Notice that such a notation does not imply that the integral over a path of $dW$ would be independent on the path. It is also not implying the existence of a potential in general.
However, and this is the key point, there are some special cases where $dW$ is exact. Modern mathematical notation usually does not use different symbols for making a distinction bteween exact and non-exact forms. However if the generic expression for work $dW$ is explicitly written as a function of its independent variables and their differentials it is possible to check explicitly whether $dW$ is exact or not.
In both your examples, in the first one, as soon as you introduced a potential energy, you were assuming an exact form, while in the second example, since you were dealing with a function of one variable, you were again implicitly dealing with an exact form, with all the consequences of the case.
In particular, in both cases, since there is a scalar function whose differential is what was called $dW$, it is consistent to call $W$ such a function and to introduce the notation $W(B)-W(A)$ for the integral of $dW$.
Of course, in the general, non-integrable case, this is not allowed.
A final word of caution about the so-called inexact differentials which plague thermodynamics. In that case the situation has some similarity with the mechanical case, but also some differences. Very briefly, work and heat in general, not only are not exact differentials, but aren't even differential at all. For a fluid system undergoing a generic non-equilibrium transformations there is no function $p$ of the volume enabling to write $dW = -p dV$. Such a notation implies as a pre-condition, a reversible quasi-static transformation. Once we have the reversible quasi-static transformation, the form may be exact or not depending on the kind of transformation (work becomes an exact form for reversible adiabatic transformations).