2. Given $|x| \leqslant 2$, the sum of the maximum and minimum values of the function $y=x-|1+x|$ is $\qquad$ .
2. -4 .
$$
\begin{array}{l}
\because|x| \leqslant 2, \text { i.e., }-2 \leqslant x \leqslant 2, \\
\therefore y=x-|1+x| \\
\quad=\left\{\begin{array}{ll}
2 x+1, & \text { when }-2 \leqslant x<-1, \\
-1, & \text { when }-1 \leqslant x \leqslant 2.
\end{array}\right.
\end{array}
$$

As shown in the figure.
Indeed, when $x=-2$, $y$ 
has the minimum value -3; when $-1 \leqslant$ $x \leqslant 2$, $y$ has the maximum value -1.

Therefore, $-3+(-1)$ $=-4$.