Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ If you would prefer to use different terms, please use the section below instead
| [@sloosch](https://github.com/sloosch) | Simon Looschen | [MIT license](http://opensource.org/licenses/MIT) |
| [@rgrinberg](https://github.com/rgrinberg) | Rudi Grinberg | [MIT license](http://opensource.org/licenses/MIT) |
| [@gabejohnson](https://github.com/gabejohnson) | Gabe Johnson | [MIT license](http://opensource.org/licenses/MIT) |
| [@dariooddenino](https://github.com/dariooddenino) | Dario Oddenino | [MIT license](http://opensource.org/licenses/MIT) |

### Contributors using Modified Terms

Expand Down
12 changes: 11 additions & 1 deletion src/Language/PureScript/Docs/Prim.hs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ primTypeErrorDocsModule = Module
, kindDoc
, textDoc
, quoteDoc
, quoteLabelDoc
, besideDoc
, aboveDoc
]
Expand Down Expand Up @@ -441,7 +442,7 @@ kindDoc = primKindOf (P.primSubName "TypeError") "Doc" $ T.unlines
[ "`Doc` is the kind of type-level documents."
, ""
, "This kind is used with the `Fail` and `Warn` type clases."
, "Build up a `Doc` with `Text`, `Quote`, `Beside`, and `Above`."
, "Build up a `Doc` with `Text`, `Quote`, `QuoteLabel`, `Beside`, and `Above`."
]

textDoc :: Declaration
Expand All @@ -462,6 +463,15 @@ quoteDoc = primTypeOf (P.primSubName "TypeError") "Quote" $ T.unlines
, "[the Custom Type Errors guide](https://github.com/purescript/documentation/blob/master/guides/Custom-Type-Errors.md)."
]

quoteLabelDoc :: Declaration
quoteLabelDoc = primTypeOf (P.primSubName "TypeError") "QuoteLabel" $ T.unlines
[ "The `QuoteLabel` type constructor will produce a `Doc` when given a `Symbol`. When the resulting `Doc` is rendered"
, "for a `Warn` or `Fail` constraint, a syntactically valid label will be produced, escaping with quotes as needed."
, ""
, "For more information, see"
, "[the Custom Type Errors guide](https://github.com/purescript/documentation/blob/master/guides/Custom-Type-Errors.md)."
]

besideDoc :: Declaration
besideDoc = primTypeOf (P.primSubName "TypeError") "Beside" $ T.unlines
[ "The Beside type constructor combines two Docs horizontally"
Expand Down
1 change: 1 addition & 0 deletions src/Language/PureScript/Environment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ primTypeErrorTypes =
, (primSubName C.typeError "Warn", (kindDoc -:> kindConstraint, ExternData))
, (primSubName C.typeError "Text", (kindSymbol -:> kindDoc, ExternData))
, (primSubName C.typeError "Quote", (kindType -:> kindDoc, ExternData))
, (primSubName C.typeError "QuoteLabel", (kindSymbol -:> kindDoc, ExternData))
, (primSubName C.typeError "Beside", (kindDoc -:> kindDoc -:> kindDoc, ExternData))
, (primSubName C.typeError "Above", (kindDoc -:> kindDoc -:> kindDoc, ExternData))
]
Expand Down
2 changes: 2 additions & 0 deletions src/Language/PureScript/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1409,6 +1409,8 @@ toTypelevelString (TypeApp (TypeConstructor f) x)
| f == primSubName C.typeError "Text" = toTypelevelString x
toTypelevelString (TypeApp (TypeConstructor f) x)
| f == primSubName C.typeError "Quote" = Just (typeAsBox x)
toTypelevelString (TypeApp (TypeConstructor f) (TypeLevelString x))
| f == primSubName C.typeError "QuoteLabel" = Just . line . prettyPrintLabel . Label $ x
toTypelevelString (TypeApp (TypeApp (TypeConstructor f) x) ret)
| f == primSubName C.typeError "Beside" =
(Box.<>) <$> toTypelevelString x <*> toTypelevelString ret
Expand Down
31 changes: 31 additions & 0 deletions tests/purs/warning/CustomWarning4.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-- @shouldWarnWith UserDefinedWarning
-- @shouldWarnWith UserDefinedWarning
-- @shouldWarnWith UserDefinedWarning
-- @shouldWarnWith UserDefinedWarning
module Main where

import Prim.TypeError (class Warn, Beside, QuoteLabel, Text)
import Prim
import Type.Row (class RowToList, Cons, Nil)

data Label (l :: Symbol) = Label

baz ::
forall row label typ.
RowToList row (Cons label typ Nil) =>
Warn (Beside (Text "Custom label ") (QuoteLabel label)) =>
Record row ->
String
baz _ = ""

baz' :: String
baz' = baz { hello: 1 }

baz'' :: String
baz'' = baz { "hello": 1 }

baz''' :: String
baz''' = baz { "h e l l o": 1 }

baz'''' :: String
baz'''' = baz { "hel\"lo": 1 }