diff --git a/message-index/messages/GHC-18157/index.md b/message-index/messages/GHC-18157/index.md new file mode 100644 index 00000000..1ee5b761 --- /dev/null +++ b/message-index/messages/GHC-18157/index.md @@ -0,0 +1,13 @@ +--- +title: GHC stage restriction +summary: A local name is used in a top-level splice, quasi-quote or annotation. +severity: error +introduced: 9.8.1 +--- + +A top-level +[Template Haskell splice](https://downloads.haskell.org/ghc/latest/docs/html/users_guide/exts/template_haskell.html#syntax), +[quasi-quote](https://downloads.haskell.org/ghc/latest/docs/users_guide/exts/template_haskell.html#template-haskell-quasi-quotation) +or +[source annotation](https://downloads.haskell.org/ghc/latest/docs/users_guide/extending_ghc.html#source-annotations). +cannot directly call a variable bound in the same module. diff --git a/message-index/messages/GHC-18157/stage-restriction-anns/after/Bar.hs b/message-index/messages/GHC-18157/stage-restriction-anns/after/Bar.hs new file mode 100644 index 00000000..be65c8c6 --- /dev/null +++ b/message-index/messages/GHC-18157/stage-restriction-anns/after/Bar.hs @@ -0,0 +1,4 @@ +module Bar (bar) where + +bar :: Integer +bar = 2 diff --git a/message-index/messages/GHC-18157/stage-restriction-anns/after/Example.hs b/message-index/messages/GHC-18157/stage-restriction-anns/after/Example.hs new file mode 100644 index 00000000..90aef7b3 --- /dev/null +++ b/message-index/messages/GHC-18157/stage-restriction-anns/after/Example.hs @@ -0,0 +1,7 @@ +module Example where + +import Bar (bar) + +{-# ANN foo bar #-} +foo :: Integer +foo = 1 diff --git a/message-index/messages/GHC-18157/stage-restriction-anns/before/Example.hs b/message-index/messages/GHC-18157/stage-restriction-anns/before/Example.hs new file mode 100644 index 00000000..1e14f83f --- /dev/null +++ b/message-index/messages/GHC-18157/stage-restriction-anns/before/Example.hs @@ -0,0 +1,8 @@ +module Example where + +{-# ANN foo bar #-} +foo :: Integer +foo = 1 + +bar :: Integer +bar = 2 diff --git a/message-index/messages/GHC-18157/stage-restriction-anns/index.md b/message-index/messages/GHC-18157/stage-restriction-anns/index.md new file mode 100644 index 00000000..b2f74be2 --- /dev/null +++ b/message-index/messages/GHC-18157/stage-restriction-anns/index.md @@ -0,0 +1,17 @@ +--- +title: A local name is used in an annotation. +--- + +`foo` and `bar` are both defined in the same module, causing the error. + +# Error Message +``` +Example.hs:3:13: error: [GHC-18157] + • GHC stage restriction: + ‘bar’ is used in a top-level splice, quasi-quote, or annotation, + and must be imported, not defined locally + • In the annotation: {-# ANN foo bar #-} + | +3 | {-# ANN foo bar #-} + | ^^^ +``` diff --git a/message-index/messages/GHC-18157/stage-restriction-qq/after/Example.hs b/message-index/messages/GHC-18157/stage-restriction-qq/after/Example.hs new file mode 100644 index 00000000..9d81908e --- /dev/null +++ b/message-index/messages/GHC-18157/stage-restriction-qq/after/Example.hs @@ -0,0 +1,7 @@ +{-# LANGUAGE QuasiQuotes #-} +module Example where + +import QQ (qq) + +foo :: String +foo = [qq|1|] diff --git a/message-index/messages/GHC-18157/stage-restriction-qq/after/QQ.hs b/message-index/messages/GHC-18157/stage-restriction-qq/after/QQ.hs new file mode 100644 index 00000000..9d1d12cb --- /dev/null +++ b/message-index/messages/GHC-18157/stage-restriction-qq/after/QQ.hs @@ -0,0 +1,12 @@ +module QQ (qq) where + +import Language.Haskell.TH.Quote +import Language.Haskell.TH + +qq :: QuasiQuoter +qq = QuasiQuoter + { quoteExp = pure . LitE . StringL + , quoteDec = undefined + , quotePat = undefined + , quoteType = undefined + } diff --git a/message-index/messages/GHC-18157/stage-restriction-qq/before/Example.hs b/message-index/messages/GHC-18157/stage-restriction-qq/before/Example.hs new file mode 100644 index 00000000..85f72a7d --- /dev/null +++ b/message-index/messages/GHC-18157/stage-restriction-qq/before/Example.hs @@ -0,0 +1,16 @@ +{-# LANGUAGE QuasiQuotes #-} +module Example where + +import Language.Haskell.TH.Quote +import Language.Haskell.TH + +qq :: QuasiQuoter +qq = QuasiQuoter + { quoteExp = pure . LitE . StringL + , quoteDec = undefined + , quotePat = undefined + , quoteType = undefined + } + +foo :: String +foo = [qq|bar|] diff --git a/message-index/messages/GHC-18157/stage-restriction-qq/index.md b/message-index/messages/GHC-18157/stage-restriction-qq/index.md new file mode 100644 index 00000000..a5f152d3 --- /dev/null +++ b/message-index/messages/GHC-18157/stage-restriction-qq/index.md @@ -0,0 +1,17 @@ +--- +title: A local name is used in a quasi-quote. +--- + +`foo` and `qq` are both defined in the same module, causing the error. + +# Error Message +``` +Example.hs:16:7: error: [GHC-18157] + • GHC stage restriction: + ‘qq’ is used in a top-level splice, quasi-quote, or annotation, + and must be imported, not defined locally + • In the quasi-quotation: [qq|bar|] + | +16 | foo = [qq|bar|] + | ^^^^^^^^^ +``` diff --git a/message-index/messages/GHC-18157/stage-restriction-splice-1/after/Example.hs b/message-index/messages/GHC-18157/stage-restriction-splice-1/after/Example.hs new file mode 100644 index 00000000..f326844b --- /dev/null +++ b/message-index/messages/GHC-18157/stage-restriction-splice-1/after/Example.hs @@ -0,0 +1,8 @@ +{-# LANGUAGE TemplateHaskell #-} +module Example where + +import Foo (foo) +import Language.Haskell.TH + +x :: Integer +x = $foo diff --git a/message-index/messages/GHC-18157/stage-restriction-splice-1/after/Foo.hs b/message-index/messages/GHC-18157/stage-restriction-splice-1/after/Foo.hs new file mode 100644 index 00000000..f6921439 --- /dev/null +++ b/message-index/messages/GHC-18157/stage-restriction-splice-1/after/Foo.hs @@ -0,0 +1,6 @@ +module Foo (foo) where + +import Language.Haskell.TH + +foo :: Q Exp +foo = pure . LitE $ IntegerL 1 diff --git a/message-index/messages/GHC-18157/stage-restriction-splice-1/before/Example.hs b/message-index/messages/GHC-18157/stage-restriction-splice-1/before/Example.hs new file mode 100644 index 00000000..0b856f75 --- /dev/null +++ b/message-index/messages/GHC-18157/stage-restriction-splice-1/before/Example.hs @@ -0,0 +1,10 @@ +{-# LANGUAGE TemplateHaskell #-} +module Example where + +import Language.Haskell.TH + +foo :: Q Exp +foo = pure . LitE $ IntegerL 1 + +x :: Integer +x = $foo diff --git a/message-index/messages/GHC-18157/stage-restriction-splice-1/index.md b/message-index/messages/GHC-18157/stage-restriction-splice-1/index.md new file mode 100644 index 00000000..2ee29986 --- /dev/null +++ b/message-index/messages/GHC-18157/stage-restriction-splice-1/index.md @@ -0,0 +1,17 @@ +--- +title: A local name is used in a top-level splice. +--- + +`x` and `foo` are both defined in the same module, causing the error. + +# Error Message +``` +Example.hs:10:6: error: [GHC-18157] + • GHC stage restriction: + ‘foo’ is used in a top-level splice, quasi-quote, or annotation, + and must be imported, not defined locally + • In the untyped splice: $foo + | +10 | x = $foo + | ^^^ +``` diff --git a/message-index/messages/GHC-18157/stage-restriction-splice-2/after/Example.hs b/message-index/messages/GHC-18157/stage-restriction-splice-2/after/Example.hs new file mode 100644 index 00000000..6db32336 --- /dev/null +++ b/message-index/messages/GHC-18157/stage-restriction-splice-2/after/Example.hs @@ -0,0 +1,9 @@ +{-# LANGUAGE TemplateHaskell #-} +module Example where + +import TH (doSomethingWithName) + +foo :: Int +foo = 1 + +doSomethingWithName 'foo diff --git a/message-index/messages/GHC-18157/stage-restriction-splice-2/after/TH.hs b/message-index/messages/GHC-18157/stage-restriction-splice-2/after/TH.hs new file mode 100644 index 00000000..62de3135 --- /dev/null +++ b/message-index/messages/GHC-18157/stage-restriction-splice-2/after/TH.hs @@ -0,0 +1,6 @@ +module TH (doSomethingWithName) where + +import Language.Haskell.TH + +doSomethingWithName :: Name -> DecsQ +doSomethingWithName x = pure [] diff --git a/message-index/messages/GHC-18157/stage-restriction-splice-2/before/Example.hs b/message-index/messages/GHC-18157/stage-restriction-splice-2/before/Example.hs new file mode 100644 index 00000000..bc5df4bd --- /dev/null +++ b/message-index/messages/GHC-18157/stage-restriction-splice-2/before/Example.hs @@ -0,0 +1,9 @@ +{-# LANGUAGE TemplateHaskell #-} +module Example where + +import TH (doSomethingWith) + +foo :: Int +foo = 1 + +doSomethingWith foo diff --git a/message-index/messages/GHC-18157/stage-restriction-splice-2/before/TH.hs b/message-index/messages/GHC-18157/stage-restriction-splice-2/before/TH.hs new file mode 100644 index 00000000..5822c522 --- /dev/null +++ b/message-index/messages/GHC-18157/stage-restriction-splice-2/before/TH.hs @@ -0,0 +1,6 @@ +module TH (doSomethingWith) where + +import Language.Haskell.TH + +doSomethingWith :: Int -> DecsQ +doSomethingWith x = pure [] diff --git a/message-index/messages/GHC-18157/stage-restriction-splice-2/index.md b/message-index/messages/GHC-18157/stage-restriction-splice-2/index.md new file mode 100644 index 00000000..b6b8ddd4 --- /dev/null +++ b/message-index/messages/GHC-18157/stage-restriction-splice-2/index.md @@ -0,0 +1,25 @@ +--- +title: A local name is used in a top-level splice as a function argument. +--- + +The error message given by GHC is slightly misleading: you cannot pass a +_variable_ bound in the same module to a top-level splice, but you can pass in +just the `Name`. The name must be bound above the splice in the module file. + +Depending on the information you need from the variable, this can be an +alternative to moving the variable binding to a different module. + +The syntax for the `Name` literal of a function `f` is `'f`, and the `Name` of a +type `T` is `''T`. To extract information from a `Name`, see `reify` in +`Language.Haskell.TH`. + +# Error Message +``` +Example.hs:9:17: error: [GHC-18157] + GHC stage restriction: + ‘foo’ is used in a top-level splice, quasi-quote, or annotation, + and must be imported, not defined locally + | +9 | doSomethingWith foo + | ^^^ +```