Fixes 8979
This commit is contained in:
parent
7107ec05de
commit
acaf2b8e76
2 changed files with 35 additions and 2 deletions
|
|
@ -705,7 +705,7 @@ proc containsResult(n: PNode): bool =
|
||||||
for i in 0..<n.safeLen:
|
for i in 0..<n.safeLen:
|
||||||
if containsResult(n[i]): return true
|
if containsResult(n[i]): return true
|
||||||
|
|
||||||
const harmless = {nkConstSection, nkTypeSection, nkEmpty, nkCommentStmt} +
|
const harmless = {nkConstSection, nkTypeSection, nkEmpty, nkCommentStmt, nkTemplateDef, nkMacroDef} +
|
||||||
declarativeDefs
|
declarativeDefs
|
||||||
|
|
||||||
proc easyResultAsgn(n: PNode): PNode =
|
proc easyResultAsgn(n: PNode): PNode =
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@ discard """
|
||||||
output: '''obj = (inner: (kind: Just, id: 7))
|
output: '''obj = (inner: (kind: Just, id: 7))
|
||||||
obj.inner.id = 7
|
obj.inner.id = 7
|
||||||
id = 7
|
id = 7
|
||||||
obj = (inner: (kind: Just, id: 7))'''
|
obj = (inner: (kind: Just, id: 7))
|
||||||
|
2'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# bug #6960
|
# bug #6960
|
||||||
|
|
@ -105,3 +106,35 @@ type
|
||||||
|
|
||||||
proc bug5137(d: MyIntDistinct) =
|
proc bug5137(d: MyIntDistinct) =
|
||||||
discard d.MyInt
|
discard d.MyInt
|
||||||
|
|
||||||
|
#-------------------------------------
|
||||||
|
# bug #8979
|
||||||
|
|
||||||
|
type
|
||||||
|
MyKind = enum
|
||||||
|
Fixed, Float
|
||||||
|
|
||||||
|
MyObject = object
|
||||||
|
someInt: int
|
||||||
|
case kind: MyKind
|
||||||
|
of Float: index: string
|
||||||
|
of Fixed: nil
|
||||||
|
|
||||||
|
MyResult = object
|
||||||
|
val: array[0..1, string]
|
||||||
|
vis: set[0..1]
|
||||||
|
|
||||||
|
import macros
|
||||||
|
|
||||||
|
func myfunc(obj: MyObject): MyResult {.raises: [].} =
|
||||||
|
template index: auto =
|
||||||
|
case obj.kind:
|
||||||
|
of Float: $obj.index
|
||||||
|
of Fixed: "Fixed"
|
||||||
|
macro to_str(a: untyped): string =
|
||||||
|
result = newStrLitNode(a.repr)
|
||||||
|
result.val[0] = index
|
||||||
|
result.val[1] = to_str(obj.kind + Ola)
|
||||||
|
|
||||||
|
let x = MyObject(someInt: 10, kind: Fixed)
|
||||||
|
echo myfunc(x).val.len
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue