make repr handle setters foo= (#17683)
This commit is contained in:
parent
cce1b24b1c
commit
877cc5e4ff
2 changed files with 17 additions and 5 deletions
|
|
@ -1327,13 +1327,16 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext, fromStmtList = false) =
|
||||||
of nkIdent: n.ident.s
|
of nkIdent: n.ident.s
|
||||||
of nkSym: n.sym.name.s
|
of nkSym: n.sym.name.s
|
||||||
else: ""
|
else: ""
|
||||||
|
proc isAlpha(n: PNode): bool =
|
||||||
|
if n.kind in {nkIdent, nkSym}:
|
||||||
|
let tmp = n.getStrVal
|
||||||
|
result = tmp.len > 0 and tmp[0] in {'a'..'z', 'A'..'Z'}
|
||||||
var useSpace = false
|
var useSpace = false
|
||||||
if i == 1 and n[0].kind == nkIdent and n[0].ident.s in ["=", "'"]:
|
if i == 1 and n[0].kind == nkIdent and n[0].ident.s in ["=", "'"]:
|
||||||
let tmp = n[1].getStrVal
|
if not n[1].isAlpha: # handle `=destroy`, `'big'
|
||||||
if tmp.len > 0 and tmp[0] in {'a'..'z', 'A'..'Z'}:
|
useSpace = true
|
||||||
# handle `=destroy`, `'big'
|
elif i == 1 and n[1].kind == nkIdent and n[1].ident.s == "=":
|
||||||
discard
|
if not n[0].isAlpha: # handle setters, e.g. `foo=`
|
||||||
else:
|
|
||||||
useSpace = true
|
useSpace = true
|
||||||
elif i > 0: useSpace = true
|
elif i > 0: useSpace = true
|
||||||
if useSpace: put(g, tkSpaces, Space)
|
if useSpace: put(g, tkSpaces, Space)
|
||||||
|
|
|
||||||
|
|
@ -163,6 +163,15 @@ proc `foo bar baz`(): int =
|
||||||
"""
|
"""
|
||||||
doAssert a2 == a
|
doAssert a2 == a
|
||||||
|
|
||||||
|
block: # setters: `foo=`
|
||||||
|
let a = deb:
|
||||||
|
proc `foo=`() = discard
|
||||||
|
doAssert a == """
|
||||||
|
|
||||||
|
proc `foo=`() =
|
||||||
|
discard
|
||||||
|
"""
|
||||||
|
|
||||||
block: # bug #14850
|
block: # bug #14850
|
||||||
block:
|
block:
|
||||||
let a = deb:
|
let a = deb:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue