## Deferred type errors and the top level

Consider

```
x = 3 -- Monomorphism restriction; we get x::alpha
f y = x::Float
g z = x::Int
```

Compiled with `-fdeferred-type-errors -dcore-lint`

we get

```
*** Core Lint errors : in result of Desugar (before optimization) ***
<no location info>: warning:
Non-CoVar has coercion type co_a1ew :: Float ~# Int
*** Offending Program ***
Rec {
co_a1ew :: Float ~# Int
[LclId[CoVarId]]
co_a1ew
= typeError
@ ('TupleRep '[])
@ (Float ~# Int)
"Foo.hs:12:7: error:\n\
\ Couldn't match expected type 'Int' with actual type 'Float' \n\
\ In the expression: x :: Int\n\
\ In an equation for 'g': g z = x :: Int\n\
\(deferred type error)"#
```

The real error is that we make a top-level binding for a coercion, which is verboten.

Here's another way to trigger the same bug

`f v = let x = \y -> (v, y : y) in True`

We get

```
*** Core Lint errors : in result of Desugar (before optimization) ***
<no location info>: warning:
Non-CoVar has coercion type co_aZY :: Any ~# [Any]
*** Offending Program ***
Rec {
co_aZY :: Any ~# [Any]
[LclId[CoVarId]]
co_aZY
= typeError
@ ('TupleRep '[])
@ (Any ~# [Any])
"Foo.hs:14:29: error:\n\
\ Occurs check: cannot construct the infinite type: a0 ~ [a0]\n\
\ In the second argument of '(:)', namely 'y' \n\
\ In the expression: y : y\n\
\ In the expression: (v, y : y)\n\
\ Relevant bindings include\n\
\ y :: a0 (bound at Foo.hs:14:16)\n\
\ x :: a0 -> (a, [a0]) (bound at Foo.hs:14:11)\n\
\(deferred type error)"#
```

What is going on? It's simple: in `floatEqualities`

we are, in both cases, floating a constraint `alpha ~ ty`

to the top level.

Could we simply *not* float equalities to the top level? Alas that means that this program would fail to compile

```
x = 3
f y = x::Int
```

because we'd get an implication constraint `forall[1] b. alpha[0] ~# Int`

, and we need to float that constraint to solve it with `alpha:=Int`

.

I'm a bit stumped about what to do here. It only matters for `-fdeferred-type-errors`

because if we report the error and stop we'll never get to that Lint problem.