diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 78a5abc8ee..fdc523bdae 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -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 diff --git a/src/Language/PureScript/Docs/Prim.hs b/src/Language/PureScript/Docs/Prim.hs index 0116788428..a6ee336193 100644 --- a/src/Language/PureScript/Docs/Prim.hs +++ b/src/Language/PureScript/Docs/Prim.hs @@ -105,6 +105,7 @@ primTypeErrorDocsModule = Module , kindDoc , textDoc , quoteDoc + , quoteLabelDoc , besideDoc , aboveDoc ] @@ -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 @@ -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" diff --git a/src/Language/PureScript/Environment.hs b/src/Language/PureScript/Environment.hs index abb25bcaa8..c806470ea3 100644 --- a/src/Language/PureScript/Environment.hs +++ b/src/Language/PureScript/Environment.hs @@ -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)) ] diff --git a/src/Language/PureScript/Errors.hs b/src/Language/PureScript/Errors.hs index fe351e4078..d4807d650b 100644 --- a/src/Language/PureScript/Errors.hs +++ b/src/Language/PureScript/Errors.hs @@ -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 diff --git a/tests/purs/warning/CustomWarning4.purs b/tests/purs/warning/CustomWarning4.purs new file mode 100644 index 0000000000..5ab9de6c40 --- /dev/null +++ b/tests/purs/warning/CustomWarning4.purs @@ -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 }