Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,248
    • Issues 4,248
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 396
    • Merge Requests 396
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Security & Compliance
    • Security & Compliance
    • Dependency List
    • License Compliance
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #11188

Closed
Open
Opened Dec 09, 2015 by andreas.abel@trac-andreas.abel

Confusing "parse error in pattern" for spurious indentation.

The following problem exists at least in ghc 7.4.2 through 7.10.1:

main = do
  putStrLn "Hello, lots of crap" $ do
    a <- return 3
    -- The following line is mis-indented, the error is incomprehensible
      c <- do
      return 5

Error:

<file>:2:3:
    Parse error in pattern: putStrLn
    Possibly caused by a missing 'do'?

The hint about "missing do" exists from ghc 7.8, but is wrong in this case. Problematic about this bug is that the wrong indentation can be arbitrary many lines from where ghc reports the (totally incomprehensible) error. My original problem is to find the syntax error here:

-- | Type check a function clause.
checkClause :: Type -> A.SpineClause -> TCM Clause
checkClause t c@(A.Clause (A.SpineLHS i x aps withPats) rhs0 wh) = do
  unless (null withPats) $ do
    typeError $ UnexpectedWithPatterns withPats
  traceCall (CheckClause t c) $ do
    aps <- expandPatternSynonyms aps
    checkLeftHandSide (CheckPatternShadowing c) (Just x) aps t $
      \ (LHSResult delta ps trhs perm) -> do
        -- Note that we might now be in irrelevant context,
        -- in case checkLeftHandSide walked over an irrelevant projection pattern.

        -- As we will be type-checking the @rhs@ in @delta@, but the final
        -- body should have bindings in the order of the pattern variables,
        -- we need to apply the permutation to the checked rhs @v@.
        let mkBody v  = foldr (\ x t -> Bind $ Abs x t) b xs
             where b  = Body $ applySubst (renamingR perm) v
                   xs = [ stringToArgName $ "h" ++ show n
                          | n <- [0..permRange perm - 1] ]

        -- introduce trailing implicits for checking the where decls
        TelV htel t0 <- telViewUpTo' (-1) (not . visible) $ unArg trhs
          (body, with) <- do
          let n = size htel
          addCtxTel htel $ checkWhere (size delta + n) wh $
            -- for the body, we remove the implicits again
            escapeContext n $
              handleRHS aps (unArgs trhs) rhs0

        escapeContext (size delta) $ checkWithFunction with

        reportSDoc "tc.lhs.top" 10 $ escapeContext (size delta) $ vcat
          [ text "Clause before translation:"
          , nest 2 $ vcat
            [ text "delta =" <+> prettyTCM delta
            , text "perm  =" <+> text (show perm)
            , text "ps    =" <+> text (show ps)
            , text "body  =" <+> text (show body)
            , text "body  =" <+> prettyTCM body
            ]
          ]

        return $
          Clause { clauseRange     = getRange i
                 , clauseTel       = killRange delta
                 , clausePerm      = perm
                 , namedClausePats = ps
                 , clauseBody      = body
                 , clauseType      = Just trhs
                 }
src/full/Agda/TypeChecking/Rules/Def.hs:328:5:
    Parse error in pattern: checkLeftHandSide
    Possibly caused by a missing 'do'?
Trac metadata
Trac field Value
Version 7.10.1
Type Bug
TypeOfFailure OtherFailure
Priority high
Resolution Unresolved
Component Compiler (Parser)
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
Edited Mar 10, 2019 by andreas.abel
Assignee
Assign to
8.4.2
Milestone
8.4.2 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#11188