Question
So suppose we have a function $f:\mathbb R^2\to \mathbb R$ for which it is given that $x\mapsto f(x,g(x))$ is smooth (i.e., $C^\infty$) for all smooth functions $g:\mathbb R\to\mathbb R$. Can we prove that $f$ is smooth as well?
I don't know whether this statement is true and honestly I wouldn't be surprised either way.
What I've tried already
Fix a point $(x_0,y_0)$. Intuitively, by taking $g(x) = \lambda x$ with $\lambda\in\mathbb R$ we see that $f$ should be at least differentiable along all directions $(1,\lambda)$ at $(x_0,y_0)$. This follows for instance by considering the curve $t\mapsto (x_0+t, y_0+\lambda t)$. Thus the only direction that is non-trivial is the vertical direction $(0,1)$. If we can show that $f$ is also differentiable in that direction then I'm confident that it will be possible to show that $f$ is differentiable. But how can we show whether $f$ is differentiable along $(0,1)$? We cannot do it directly from the fact that $f(x,g(x))$ is smooth, but perhaps we can use a limiting argument, letting the slope of the curve $(t,g(t))$ tend to infinity?
When we know that $f$ is differentiable, it will probably be possible using an inductive argument to prove that $f$ is smooth (i.e., $C^\infty$).
Any help is appreciated.
EDIT. If found a closely related result, namely Boman's theorem, which says basically says that $f$ is smooth if and only if $f\circ\gamma$ is smooth for all smooth curves $\gamma:\mathbb R\to\mathbb R^2$. I feel like the statement of my question should probably be reducible to this theorem. The only difficulty is that we don't necessarily know if our $f$ is differentiable along vertical curves, but perhaps this follows in some way.