Fix Monoid instances for ForeignLib & Executable
commit54183f2353dfa730d86e1503abc792f49f85c586
authorMatthew Pickering <matthewtpickering@gmail.com>
Fri, 22 Dec 2023 13:13:04 +0000 (22 14:13 +0100)
committerMikolaj <281893+Mikolaj@users.noreply.github.com>
Sat, 13 Jan 2024 19:58:59 +0000 (13 19:58 +0000)
tree0c326d894c64994ddf0edb89dbf1ebdae3085391
parent973b6ed108a9c90daf40e7403df7ab0975f305ea
Fix Monoid instances for ForeignLib & Executable

The Semigroup and Monoid instances for ForeignLib were completely
broken: for the `foreignLibVersionInfo` and `foreignLibVersionInfo`,
we essentially had the following:

  mempty :: Maybe XYZ
  mempty = Nothing

  (<>) :: Maybe XYZ -> Maybe XYZ -> Maybe XYZ
  _ <> b = b

which is obviously not a valid Monoid, as `Just x <> Nothing = Nothing`,
violating the identity law.

The Semigroup instance for Executable was also deeply suspicious, as
it combined the module paths, which makes no sense. Now we instead error
if the two module paths are different (and both nonempty).
Cabal-syntax/src/Distribution/Types/Executable.hs
Cabal-syntax/src/Distribution/Types/ForeignLib.hs
Cabal-syntax/src/Distribution/Types/UnqualComponentName.hs