computeReturnValue opts cc sc spec ty (Just val) =
  do val' <- resolveSetupValueJVM opts cc sc spec val
     let fail_ = failure (spec ^. MS.csLoc) (BadReturnSpecification (Some ty))
     case val' of
       IVal i ->
         case testEquality ty CJ.intRepr of
           Just Refl -> return i
           Nothing -> fail_
       LVal l ->
         case testEquality ty CJ.longRepr of
           Just Refl -> return l
           Nothing -> fail_
       RVal r ->
         case testEquality ty CJ.refRepr of
           Just Refl -> return r
           Nothing -> fail_


------------------------------------------------------------------------

-- | Assign the given pointer value to the given allocation index in
-- the current substitution. If there is already a binding for this
-- index, then add a pointer-equality constraint.
computeReturnValue opts cc sc spec ty (Just val) =
  do val' <- resolveSetupValueJVM opts cc sc spec val
     let fail_ = failure (spec ^. MS.csLoc) (BadReturnSpecification (Some ty))
     case val' of
       IVal i ->
         case testEquality ty CJ.intRepr of
           Just Refl -> return i
           Nothing -> fail_
       LVal l ->
         case testEquality ty CJ.longRepr of
           Just Refl -> return l
           Nothing -> fail_
       RVal r ->
         case testEquality ty CJ.refRepr of
           Just Refl -> return r
           Nothing -> fail_


------------------------------------------------------------------------

-- | Assign the given pointer value to the given allocation index in
-- the current substitution. If there is already a binding for this
-- index, then add a pointer-equality constraint.
computeReturnValue opts cc sc spec ty (Just val) =
  do val' <- resolveSetupValueJVM opts cc sc spec val
     let fail_ = failure (spec ^. MS.csLoc) (BadReturnSpecification (Some ty))
     case val' of
       IVal i ->
         case testEquality ty CJ.intRepr of
           Just Refl -> return i
           Nothing -> fail_
       LVal l ->
         case testEquality ty CJ.longRepr of
           Just Refl -> return l
           Nothing -> fail_
       RVal r ->
         case testEquality ty CJ.refRepr of
           Just Refl -> return r
           Nothing -> fail_


------------------------------------------------------------------------

-- | Assign the given pointer value to the given allocation index in
-- the current substitution. If there is already a binding for this
-- index, then add a pointer-equality constraint.