Make dsWhenNoErrs return an error of the correct type instead of unitExpr
This fixes #18149 (closed) & #14765 (closed) by passing the type of the resulting Core expression as an extra argument to dsWhenNoErrs
, and use it when there is a representation-polymorphism error to return an error expression of the correct type, instead of ()
(which has the wrong type and thus could cause a cascade of errors downstream).
The note [Desugaring representation-polymorphic applications] in GHC.HsToCore.Utils explains the mechanism in more detail.