Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,349
    • Issues 5,349
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 574
    • Merge requests 574
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #15645
Closed
Open
Issue created Sep 14, 2018 by Neil Mitchell@ndmitchellReporter

TypeChecking of Monad patterns incorrect with RebindableSyntax and OverloadedStrings

Using GHC 8.4.3, I'd expect the following to work:

{-# LANGUAGE RebindableSyntax, OverloadedStrings #-}

module Fail where

import Prelude hiding (fail)

foo x = do
    Just y <- x
    return y

newtype Text = Text String

fail :: Text -> a
fail (Text x) = error x

fromString :: String -> Text
fromString = Text

But it fails with:

Fail.hs:8:5-15: error:
    * Couldn't match expected type `[Char]' with actual type `Text'
    * In a stmt of a 'do' block: Just y <- x
      In the expression:
        do Just y <- x
           return y
      In an equation for `foo':
          foo x
            = do Just y <- x
                 return y
  |
8 |     Just y <- x
  |     ^^^^^^^^^^^

Given the enabled extensions, I'd expect foo to desugar as:

foo x = x >>= \v -> case v of
    Just y -> return y
    _ -> fail (fromString "pattern match error")

But looking at TcMatches.tcMonadFailOp it checks the fail operation (which is literally fail) takes an argument of type tyString (e.g. [Char]). One way around that would be to make the "fail-op" being passed around be fail . fromString if the appropriate extensions are enabled.

Trac metadata
Trac field Value
Version 8.4.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC ndmitchell@gmail.com
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking