yi-editor / yi

The Haskell-Scriptable Editor
GNU General Public License v2.0
1.51k stars 203 forks source link

yi does not build with -XMonadFailDesugaring enabled (default in GHC 8.6+) #1102

Open chessai opened 6 years ago

chessai commented 6 years ago

-XMonadFailDesugaring is enabled by default with GHC 8.6+. There are some failable patterns involving BufferM that cause Yi to fail to compile, because BufferM doesn't have a MonadFail instance.

chessai commented 6 years ago

Apologies for the fact that I forgot to copy the error I was getting the other day. There's likely more than one place, the easiest way to see all of them is either with GHC 8.6 or setting default-extensions: MonadFailDesugaring in your .cabal files

zenhack commented 6 years ago

Just ran into this. I don't really have anything to add, except ftr this is the error output I got:

[33 of 70] Compiling Yi.Buffer.Misc   ( src/Yi/Buffer/Misc.hs, dist/build/Yi/Buffer/Misc.o )

src/Yi/Buffer/Misc.hs:453:25-95: error:
    • No instance for (Control.Monad.Fail.MonadFail BufferM)
        arising from a do statement
        with the failable pattern ‘Just mrks’
    • In a stmt of a 'do' block:
        Just mrks <- uses
                       winMarksA (M.lookup $ wkey (b ^. lastActiveWindowA))
      In the expression:
        do Just mrks <- uses
                          winMarksA (M.lookup $ wkey (b ^. lastActiveWindowA))
           forM mrks getMarkValueB
      In a stmt of a 'do' block:
        newMarkValues <- if wkey (b ^. lastActiveWindowA) == def then
                             return
                               MarkSet
                                 {insMark = MarkValue 0 Forward, selMark = MarkValue 0 Backward,
                                  fromMark = MarkValue 0 Backward}
                         else
                             do Just mrks <- uses
                                               winMarksA (M.lookup $ wkey (b ^. lastActiveWindowA))
                                forM mrks getMarkValueB
    |
453 |                         Just mrks  <- uses winMarksA (M.lookup $ wkey (b ^. lastActiveWindowA))
    |                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

src/Yi/Buffer/Misc.hs:873:3-30: error:
    • No instance for (Control.Monad.Fail.MonadFail BufferM)
        arising from a do statement
        with the failable pattern ‘Just !ms’
    • In a stmt of a 'do' block: Just !ms <- getMarks =<< ask
      In the expression:
        do Just !ms <- getMarks =<< ask
           return ms
      In an equation for ‘askMarks’:
          askMarks
            = do Just !ms <- getMarks =<< ask
                 return ms
    |
873 |   Just !ms <- getMarks =<< ask
    |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cabal: Failed to build yi-core-0.18.0 (which is required by exe:yi from
yi-0.18.0). See the build log above for details.
xaverdh commented 5 years ago

I have a quick and dirty (may eat your data) patch here: https://github.com/xaverdh/yi/commits/monad-fail Actually it probably won't eat your data.

chessai commented 5 years ago

Do we really want the possibility for 'error' to occur there? Is there not a way to just avoid the failable pattern?

xaverdh commented 5 years ago

Its not just failable patterns. printableChar for example calls fail explicitly. The implementation of MonadInteract also has an Fails constructor which deals with this.

xaverdh commented 5 years ago

Ah ok, you are probably referring to BufferM / EditorM. I don't know about that one.

xaverdh commented 5 years ago

Ok, its mostly about Marks. getMarks returns a Maybe value, but askMarks (which is used all over the place in that file) then discards it, so maybe its presence is/should be an invariant? runBufferFull looks like it should be, but then I don't understand why getMarks exists / is exported at all.

xaverdh commented 5 years ago

I opened a pull request #1108 based on a different branch, where I attempt to do things properly. We can discuss details there.