forked from nim-lang/Nim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
give type macro pragmas unary type section with experimental switch
closes nim-lang#13830, fixes nim-lang#15334, fixes nim-lang#18864
- Loading branch information
Showing
5 changed files
with
85 additions
and
7 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
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
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
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
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,49 @@ | ||
discard """ | ||
nimout: ''' | ||
TypeSection | ||
TypeDef | ||
PragmaExpr | ||
Sym "X" | ||
Pragma | ||
Empty | ||
ObjectTy | ||
Empty | ||
Empty | ||
Empty | ||
''' | ||
""" | ||
|
||
import macros | ||
|
||
{.experimental: "typedTypeMacroPragma".} | ||
|
||
block: # changelog entry | ||
macro foo(def: typed) = | ||
assert def.kind == nnkTypeSection # previously nnkTypeDef | ||
assert def.len == 1 | ||
assert def[0].kind == nnkTypeDef | ||
result = def | ||
|
||
type Obj {.foo.} = object | ||
x, y: int | ||
|
||
let obj = Obj(x: 1, y: 2) | ||
|
||
block: # issue #18864 | ||
macro test(n: typed): untyped = | ||
echo n.treeRepr | ||
result = n | ||
|
||
type | ||
X {.test.} = object | ||
var x = X() | ||
|
||
block: # issue #15334 | ||
macro entity(entityType: typed) = | ||
result = entityType | ||
|
||
type | ||
RootEntity = ref object of RootObj | ||
Player {.entity.} = ref object of RootEntity | ||
x, y: int | ||
var foo = Player() |