-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
4 changes: 4 additions & 0 deletions
4
message-index/messages/GHC-18157/stage-restriction-anns/after/Bar.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module Bar (bar) where | ||
|
||
bar :: Integer | ||
bar = 2 |
7 changes: 7 additions & 0 deletions
7
message-index/messages/GHC-18157/stage-restriction-anns/after/Example.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Example where | ||
|
||
import Bar (bar) | ||
|
||
{-# ANN foo bar #-} | ||
foo :: Integer | ||
foo = 1 |
8 changes: 8 additions & 0 deletions
8
message-index/messages/GHC-18157/stage-restriction-anns/before/Example.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Example where | ||
|
||
{-# ANN foo bar #-} | ||
foo :: Integer | ||
foo = 1 | ||
|
||
bar :: Integer | ||
bar = 2 |
17 changes: 17 additions & 0 deletions
17
message-index/messages/GHC-18157/stage-restriction-anns/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 #-} | ||
| ^^^ | ||
``` |
7 changes: 7 additions & 0 deletions
7
message-index/messages/GHC-18157/stage-restriction-qq/after/Example.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{-# LANGUAGE QuasiQuotes #-} | ||
module Example where | ||
|
||
import QQ (qq) | ||
|
||
foo :: String | ||
foo = [qq|1|] |
12 changes: 12 additions & 0 deletions
12
message-index/messages/GHC-18157/stage-restriction-qq/after/QQ.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
16 changes: 16 additions & 0 deletions
16
message-index/messages/GHC-18157/stage-restriction-qq/before/Example.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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|] |
17 changes: 17 additions & 0 deletions
17
message-index/messages/GHC-18157/stage-restriction-qq/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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|] | ||
| ^^^^^^^^^ | ||
``` |
8 changes: 8 additions & 0 deletions
8
message-index/messages/GHC-18157/stage-restriction-splice-1/after/Example.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
module Example where | ||
|
||
import Foo (foo) | ||
import Language.Haskell.TH | ||
|
||
x :: Integer | ||
x = $foo |
6 changes: 6 additions & 0 deletions
6
message-index/messages/GHC-18157/stage-restriction-splice-1/after/Foo.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Foo (foo) where | ||
|
||
import Language.Haskell.TH | ||
|
||
foo :: Q Exp | ||
foo = pure . LitE $ IntegerL 1 |
10 changes: 10 additions & 0 deletions
10
message-index/messages/GHC-18157/stage-restriction-splice-1/before/Example.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
17 changes: 17 additions & 0 deletions
17
message-index/messages/GHC-18157/stage-restriction-splice-1/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
| ^^^ | ||
``` |
9 changes: 9 additions & 0 deletions
9
message-index/messages/GHC-18157/stage-restriction-splice-2/after/Example.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
module Example where | ||
|
||
import TH (doSomethingWithName) | ||
|
||
foo :: Int | ||
foo = 1 | ||
|
||
doSomethingWithName 'foo |
6 changes: 6 additions & 0 deletions
6
message-index/messages/GHC-18157/stage-restriction-splice-2/after/TH.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module TH (doSomethingWithName) where | ||
|
||
import Language.Haskell.TH | ||
|
||
doSomethingWithName :: Name -> DecsQ | ||
doSomethingWithName x = pure [] |
9 changes: 9 additions & 0 deletions
9
message-index/messages/GHC-18157/stage-restriction-splice-2/before/Example.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{-# LANGUAGE TemplateHaskell #-} | ||
module Example where | ||
|
||
import TH (doSomethingWith) | ||
|
||
foo :: Int | ||
foo = 1 | ||
|
||
doSomethingWith foo |
6 changes: 6 additions & 0 deletions
6
message-index/messages/GHC-18157/stage-restriction-splice-2/before/TH.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module TH (doSomethingWith) where | ||
|
||
import Language.Haskell.TH | ||
|
||
doSomethingWith :: Int -> DecsQ | ||
doSomethingWith x = pure [] |
25 changes: 25 additions & 0 deletions
25
message-index/messages/GHC-18157/stage-restriction-splice-2/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
| ^^^ | ||
``` |