Skip to content

Commit cda514b

Browse files
committed
Add GHC-18157
1 parent 2c280d5 commit cda514b

File tree

18 files changed

+197
-0
lines changed

18 files changed

+197
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: GHC stage restriction
3+
summary: A local name is used in a top-level splice, quasi-quote or annotation.
4+
severity: error
5+
introduced: 9.8.1
6+
---
7+
8+
A top-level
9+
[Template Haskell splice](https://downloads.haskell.org/ghc/latest/docs/html/users_guide/exts/template_haskell.html#syntax),
10+
[quasi-quote](https://downloads.haskell.org/ghc/latest/docs/users_guide/exts/template_haskell.html#template-haskell-quasi-quotation)
11+
or
12+
[source annotation](https://downloads.haskell.org/ghc/latest/docs/users_guide/extending_ghc.html#source-annotations).
13+
cannot directly call a variable bound in the same module.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Bar (bar) where
2+
3+
bar :: Integer
4+
bar = 2
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Example where
2+
3+
import Bar (bar)
4+
5+
{-# ANN foo bar #-}
6+
foo :: Integer
7+
foo = 1
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Example where
2+
3+
{-# ANN foo bar #-}
4+
foo :: Integer
5+
foo = 1
6+
7+
bar :: Integer
8+
bar = 2
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: A local name is used in an annotation.
3+
---
4+
5+
`foo` and `bar` are both defined in the same module, causing the error.
6+
7+
# Error Message
8+
```
9+
Example.hs:3:13: error: [GHC-18157]
10+
• GHC stage restriction:
11+
‘bar’ is used in a top-level splice, quasi-quote, or annotation,
12+
and must be imported, not defined locally
13+
• In the annotation: {-# ANN foo bar #-}
14+
|
15+
3 | {-# ANN foo bar #-}
16+
| ^^^
17+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{-# LANGUAGE QuasiQuotes #-}
2+
module Example where
3+
4+
import QQ (qq)
5+
6+
foo :: String
7+
foo = [qq|1|]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module QQ (qq) where
2+
3+
import Language.Haskell.TH.Quote
4+
import Language.Haskell.TH
5+
6+
qq :: QuasiQuoter
7+
qq = QuasiQuoter
8+
{ quoteExp = pure . LitE . StringL
9+
, quoteDec = undefined
10+
, quotePat = undefined
11+
, quoteType = undefined
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{-# LANGUAGE QuasiQuotes #-}
2+
module Example where
3+
4+
import Language.Haskell.TH.Quote
5+
import Language.Haskell.TH
6+
7+
qq :: QuasiQuoter
8+
qq = QuasiQuoter
9+
{ quoteExp = pure . LitE . StringL
10+
, quoteDec = undefined
11+
, quotePat = undefined
12+
, quoteType = undefined
13+
}
14+
15+
foo :: String
16+
foo = [qq|bar|]
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: A local name is used in a quasi-quote.
3+
---
4+
5+
`foo` and `qq` are both defined in the same module, causing the error.
6+
7+
# Error Message
8+
```
9+
Example.hs:16:7: error: [GHC-18157]
10+
• GHC stage restriction:
11+
‘qq’ is used in a top-level splice, quasi-quote, or annotation,
12+
and must be imported, not defined locally
13+
• In the quasi-quotation: [qq|bar|]
14+
|
15+
16 | foo = [qq|bar|]
16+
| ^^^^^^^^^
17+
```
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
module Example where
3+
4+
import Foo (foo)
5+
import Language.Haskell.TH
6+
7+
x :: Integer
8+
x = $foo

0 commit comments

Comments
 (0)