Skip to content

Make Lint check for bad uses of `unsafeCoerce`

I think it would be a great idea for Core Lint to check for uses of unsafeCoerce that don't obey the rules. It won't catch all cases, of course, but it would have caught #9035 (closed). Specficially, look for:

  • Coercions between lifted and unboxed types
  • Coercion between unboxed types of different sizes
  • Coercion between unboxed ints and floats.

Would anyone like to make a patch for this? Anything that can be checked by Core Lint, should be checked!

I'm afraid I don't know where to look for the reason for the int/float difficulty. I'd write a tiny function that exhibits the unsafe conversion and look the code it generates.

Wiki design page BadUnsafeCoercions

Edited by Simon Peyton Jones
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information