# Piecewise defined map that is not a morphism

Assume that I am given two varieties $$X,Y$$ and a map $$\phi:X\to Y$$ such that $$\phi\mid_{X^{smth}}:X^{smth}\to Y^{smth}$$ is an isomorphism and also $$\phi\mid_{X^{sgl}}:X^{sgl}\to Y^{sgl}$$ is an isomorphism, where $$X^{smth}$$ denotes the smooth locus and $$X^{sgl}$$ denotes the singular locus. An example of such a map would be a piecewise defined map, defined on the smooth locus as some isomorphism and on the singular locus as another isomorphism.

I expect that such a map is just not very well-defined so it should not be a morphism. Unfortunately, I was unable to come up with a counterexample. Can someone help out?

Let $$A = k[t^3,t^4] \subset k[t]$$ and $$B = k[t^2,t^3] \subset k[t]$$ and set $$X = Spec(A)$$, $$Y = Spec(B)$$. The embedding $$A \to B$$ induces a morphism $$\psi \colon Y \to X$$ which induces isomorphisms of smooth and singular loci of $$X$$ and $$Y$$, but itself is not an isomorphism. Consequently, the "inverse" of $$\psi$$ is a map with the required properties which is not a morphism.