Skip to content

"default" expressions in persistentmodels files no longer parse as before #1620

@m4dc4p

Description

@m4dc4p

Something changed between persistent-2.15.1.0 & persistent-2.16.0.0 (and later); "default" expressions that used to parse now fail to compile.

The quasiquoter does not like the expression default=to_jsonb('{"!v":0}'::json) under 2.18; fortunately there is a workaround in this case (default='{"!v":0}'::jsonb) but that might also trigger an unnecessary migration.

I've tested with GHC 9.10.3 and 9.12.2, with the same results.

This program demonstrates the bug with ghc --make (and the appropriate persistent library installed):

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}

module Main where

import Data.Text (Text)
import Database.Persist.TH (mkPersist, persistLowerCase, share, sqlSettings)

share
  [mkPersist sqlSettings]
  [persistLowerCase|
DBThing
  name Text
  metadata1 Text default=to_jsonb('{"!v":0}'::json)
  metadata2 Text default='{"!v":0}'::jsonb
  deriving Show Eq
|]

main :: IO ()
main = pure ()

Compiled as above, GHC will report:

persistent-default-bug.hs:15:21: error: [GHC-39584]
    • persistent-default-bug.hs:4:36:
  |
4 |   metadata1 Text default=to_jsonb('{"!v":0}'::json)
  |                                    ^
unexpected '{'
expecting '!', '"', ''', '(', ')', ',', '-', '.', ':', '[', '\', ']', '_', '~', alphanumeric character, assignment expression, end of input, newline, parenthetical, or plain attribute

    • In the quasi-quotation:
        [persistLowerCase|
DBThing
  name Text
  metadata1 Text default=to_jsonb('{"!v":0}'::json)
  metadata2 Text default='{"!v":0}'::jsonb
  deriving Show Eq
|]
   |
15 |   [persistLowerCase|
   |                     ^...

If metadata1 is commented out, the program compiles as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions