-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #1969, closes #7547, closes #7737, closes #11838, closes #12283, closes #12714, closes #12720, closes #14053, closes #16118, closes #19670, closes #22645 I was going to wait on these but regression tests even for recent PRs are turning out to be important in wide reaching PRs like #24010. The other issues with the working label felt either finnicky (#7385, #9156, #12732, #15247), excessive to test (#12405, #12424, #17527), or I just don't know what fixed them/what the issue was (#16128: the PR link gives a server error by Github, #12457, #12487).
- Loading branch information
Showing
5 changed files
with
221 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,86 @@ | ||
discard """ | ||
nimout: ''' | ||
type | ||
Bob = object | ||
type | ||
Another = object | ||
''' | ||
""" | ||
|
||
block: # issue #22645 | ||
type | ||
Opt[T] = object | ||
FutureBase = ref object of RootObj | ||
Future[T] = ref object of FutureBase ## Typed future. | ||
internalValue: T ## Stored value | ||
template err[T](E: type Opt[T]): E = E() | ||
proc works(): Future[Opt[int]] {.stackTrace: off, gcsafe, raises: [].} = | ||
var chronosInternalRetFuture: FutureBase | ||
template result(): untyped {.used.} = | ||
Future[Opt[int]](chronosInternalRetFuture).internalValue | ||
result = err(type(result)) | ||
proc breaks(): Future[Opt[int]] {.stackTrace: off, gcsafe, raises: [].} = | ||
var chronosInternalRetFuture: FutureBase | ||
template result(): untyped {.used.} = | ||
cast[Future[Opt[int]]](chronosInternalRetFuture).internalValue | ||
result = err(type(result)) | ||
|
||
import macros | ||
|
||
block: # issue #16118 | ||
macro thing(name: static[string]) = | ||
result = newStmtList( | ||
nnkTypeSection.newTree( | ||
nnkTypeDef.newTree( | ||
ident(name), | ||
newEmptyNode(), | ||
nnkObjectTy.newTree( | ||
newEmptyNode(), | ||
newEmptyNode(), | ||
nnkRecList.newTree())))) | ||
template foo(name: string): untyped = | ||
thing(name) | ||
expandMacros: | ||
foo("Bob") | ||
block: | ||
expandMacros: | ||
foo("Another") | ||
|
||
block: # issue #19670 | ||
type | ||
Past[Z] = object | ||
OpenObject = object | ||
|
||
macro rewriter(prc: untyped): untyped = | ||
prc.body.add(nnkCall.newTree( | ||
prc.params[0] | ||
)) | ||
prc | ||
|
||
macro macroAsync(name, restype: untyped): untyped = | ||
quote do: | ||
proc `name`(): Past[seq[`restype`]] {.rewriter.} = discard | ||
|
||
macroAsync(testMacro, OpenObject) | ||
|
||
import asyncdispatch | ||
|
||
block: # issue #11838 long | ||
type | ||
R[P] = object | ||
updates: seq[P] | ||
D[T, P] = ref object | ||
ps: seq[P] | ||
t: T | ||
proc newD[T, P](ps: seq[P], t: T): D[T, P] = | ||
D[T, P](ps: ps, t: t) | ||
proc loop[T, P](d: D[T, P]) = | ||
var results = newSeq[Future[R[P]]](10) | ||
let d = newD[string, int](@[1], "") | ||
d.loop() | ||
|
||
block: # issue #11838 minimal | ||
type R[T] = object | ||
proc loop[T]() = | ||
discard newSeq[R[R[T]]]() | ||
loop[int]() |
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,61 @@ | ||
discard """ | ||
nimout: ''' | ||
seq[int] | ||
CustomSeq[int] | ||
''' | ||
""" | ||
|
||
import macros, typetraits, sequtils | ||
|
||
block: # issue #7737 original | ||
type | ||
CustomSeq[T] = object | ||
data: seq[T] | ||
|
||
proc getSubType(T: NimNode): NimNode = | ||
echo getTypeInst(T).repr | ||
result = getTypeInst(T)[1] | ||
|
||
macro typed_helper(x: varargs[typed]): untyped = | ||
let foo = getSubType(x[0]) | ||
result = quote do: discard | ||
|
||
macro untyped_heavylifting(x: varargs[untyped]): untyped = | ||
var containers = nnkArgList.newTree() | ||
for arg in x: | ||
case arg.kind: | ||
of nnkInfix: | ||
if eqIdent(arg[0], "in"): | ||
containers.add arg[2] | ||
else: | ||
discard | ||
result = quote do: | ||
typed_helper(`containers`) | ||
var a, b, c: seq[int] | ||
untyped_heavylifting z in c, x in a, y in b: | ||
discard | ||
## The following gives me CustomSeq instead | ||
## of CustomSeq[int] in getTypeInst | ||
var u, v, w: CustomSeq[int] | ||
untyped_heavylifting z in u, x in v, y in w: | ||
discard | ||
|
||
block: # issue #7737 comment | ||
type | ||
CustomSeq[T] = object | ||
data: seq[T] | ||
# when using just one argument, `foo` and `bar` should be exactly | ||
# identical. | ||
macro foo(arg: typed): string = | ||
result = newLit(arg.getTypeInst.repr) | ||
macro bar(args: varargs[typed]): untyped = | ||
result = newTree(nnkBracket) | ||
for arg in args: | ||
result.add newLit(arg.getTypeInst.repr) | ||
var | ||
a: seq[int] | ||
b: CustomSeq[int] | ||
doAssert foo(a) == "seq[int]" | ||
doAssert bar(a) == ["seq[int]"] | ||
doAssert foo(b) == "CustomSeq[int]" | ||
doAssert bar(b) == ["CustomSeq[int]"] |
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