Revert "Revert "Make sure type gets set consistently in folded binary operations""

This patch was originally reverted only because a dependency patch failed a
buggy Chromium test.

This reverts commit aebd002d00d39858819c58bad1970df121b78e1b.

TEST=dEQP-GLES3.functional.shaders.constant_expressions.*
BUG=angleproject:817

Change-Id: Ia5acf15518ea89717c0cfe1398cb18ea27be5b19
Reviewed-on: https://chromium-review.googlesource.com/275811
Tested-by: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/Intermediate.cpp b/src/compiler/translator/Intermediate.cpp
index 1d8b36b..5762b1e 100644
--- a/src/compiler/translator/Intermediate.cpp
+++ b/src/compiler/translator/Intermediate.cpp
@@ -57,19 +57,10 @@
     if (!node->promote(mInfoSink))
         return NULL;
 
-    //
     // See if we can fold constants.
-    //
-    TIntermConstantUnion *leftTempConstant = left->getAsConstantUnion();
-    TIntermConstantUnion *rightTempConstant = right->getAsConstantUnion();
-    if (leftTempConstant && rightTempConstant)
-    {
-        TIntermTyped *typedReturnNode =
-            leftTempConstant->fold(node->getOp(), rightTempConstant, mInfoSink);
-
-        if (typedReturnNode)
-            return typedReturnNode;
-    }
+    TIntermTyped *foldedNode = node->fold(mInfoSink);
+    if (foldedNode)
+        return foldedNode;
 
     return node;
 }
@@ -143,7 +134,7 @@
 
     if (childTempConstant)
     {
-        TIntermTyped *newChild = childTempConstant->fold(op, nullptr, mInfoSink);
+        TIntermTyped *newChild = childTempConstant->foldUnary(op, mInfoSink);
 
         if (newChild)
             return newChild;