When using a texture access funcion, like texture2D, in a shader, it returns a vec4 value.
Of course if the texture accessed through the sampler is an RGBA texture this values match the Red, Green, Blue and Alpha values, but what happens exactly if it is a rgb, luminance, alpha, luminance_alpha or intensity value?
(If found no information about that in both the gl2 and glsl specs)
Look again in the OpenGL specs.
It’s described in the pixel operations, chapter 3.6 Conversion to RGB and Final Expansion to RGBA or see table 3.13.
Chapter 3.18 Table 3.15 shows how the input is mapped to the internalFormat.