Shader versions must match.

Per GLSL_ES_Specification_3.00.4 paragraph 3.3 Version Declaration:
"Shaders declaring version 3.00 of the shading language
cannot be linked with shaders declaring version 1.00."

BUG=angleproject:1361
TEST=GLSLTest_ES3.VersionMismatch

Change-Id: Icee672b798dcdb41a189e4a6459c4e643daf1fa6
Reviewed-on: https://chromium-review.googlesource.com/353182
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Commit-Queue: Yuly Novikov <ynovikov@chromium.org>
diff --git a/src/libANGLE/Program.cpp b/src/libANGLE/Program.cpp
index 98fa9ae..65cde2f 100644
--- a/src/libANGLE/Program.cpp
+++ b/src/libANGLE/Program.cpp
@@ -462,6 +462,13 @@
     }
     ASSERT(mState.mAttachedVertexShader->getType() == GL_VERTEX_SHADER);
 
+    if (mState.mAttachedFragmentShader->getShaderVersion() !=
+        mState.mAttachedVertexShader->getShaderVersion())
+    {
+        mInfoLog << "Fragment shader version does not match vertex shader version.";
+        return Error(GL_NO_ERROR);
+    }
+
     if (!linkAttributes(data, mInfoLog, mAttributeBindings, mState.mAttachedVertexShader))
     {
         return Error(GL_NO_ERROR);
diff --git a/src/tests/gl_tests/GLSLTest.cpp b/src/tests/gl_tests/GLSLTest.cpp
index e0b1d94..e8e694e 100644
--- a/src/tests/gl_tests/GLSLTest.cpp
+++ b/src/tests/gl_tests/GLSLTest.cpp
@@ -624,6 +624,39 @@
     EXPECT_NE(0u, program);
 }
 
+// Verify that linking shaders declaring different shading language versions fails.
+TEST_P(GLSLTest_ES3, VersionMismatch)
+{
+    const std::string fragmentShaderSource100 =
+        "precision mediump float;\n"
+        "varying float v_varying;\n"
+        "void main() { gl_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
+
+    const std::string vertexShaderSource100 =
+        "attribute vec4 a_position;\n"
+        "varying float v_varying;\n"
+        "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
+
+    const std::string fragmentShaderSource300 =
+        "#version 300 es\n"
+        "precision mediump float;\n"
+        "in float v_varying;\n"
+        "out vec4 my_FragColor;\n"
+        "void main() { my_FragColor = vec4(v_varying, 0, 0, 1.0); }\n";
+
+    const std::string vertexShaderSource300 =
+        "#version 300 es\n"
+        "in vec4 a_position;\n"
+        "out float v_varying;\n"
+        "void main() { v_varying = a_position.x; gl_Position = a_position; }\n";
+
+    GLuint program = CompileProgram(vertexShaderSource300, fragmentShaderSource100);
+    EXPECT_EQ(0u, program);
+
+    program = CompileProgram(vertexShaderSource100, fragmentShaderSource300);
+    EXPECT_EQ(0u, program);
+}
+
 TEST_P(GLSLTest, InvariantVaryingOut)
 {
     // TODO(geofflang): Some OpenGL drivers have compile errors when varyings do not have matching