diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2021-04-09 02:37:10 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-09 09:37:10 +0200 |
commit | 877cc5e4ff63ddd03c5bc057379adb5a929d8ac2 (patch) | |
tree | 3bcfdbb12228ca01fa94ffa3c7b8c88541a7c0fa /compiler | |
parent | cce1b24b1cc3860ff503668761d2798b1b1d1ef0 (diff) | |
download | Nim-877cc5e4ff63ddd03c5bc057379adb5a929d8ac2.tar.gz |
make repr handle setters `foo=` (#17683)
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/renderer.nim | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/compiler/renderer.nim b/compiler/renderer.nim index 78e2fe20e..b3b0adc01 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -1327,13 +1327,16 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext, fromStmtList = false) = of nkIdent: n.ident.s of nkSym: n.sym.name.s 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 if i == 1 and n[0].kind == nkIdent and n[0].ident.s in ["=", "'"]: - let tmp = n[1].getStrVal - if tmp.len > 0 and tmp[0] in {'a'..'z', 'A'..'Z'}: - # handle `=destroy`, `'big' - discard - else: + if not n[1].isAlpha: # handle `=destroy`, `'big' + useSpace = true + elif i == 1 and n[1].kind == nkIdent and n[1].ident.s == "=": + if not n[0].isAlpha: # handle setters, e.g. `foo=` useSpace = true elif i > 0: useSpace = true if useSpace: put(g, tkSpaces, Space) |