diff options
author | metagn <10591326+metagn@users.noreply.github.com> | 2022-07-12 19:03:58 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-12 18:03:58 +0200 |
commit | 5c510a9ab96f265ffb0323a18deadb5bb175cfdc (patch) | |
tree | c8d72c0ea6d6d5cd5556549ca8623cf2be728d99 /compiler | |
parent | a97b00ad8d18d836d693c224909b607d2af0c4b1 (diff) | |
download | Nim-5c510a9ab96f265ffb0323a18deadb5bb175cfdc.tar.gz |
allow dots in defined() (#20010)
* allow dots in defined() refs https://github.com/nim-lang/RFCs/issues/181 * mention accents in older versions
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/semexprs.nim | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index e07a98417..fed9cae21 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1938,11 +1938,23 @@ proc semYield(c: PContext, n: PNode): PNode = elif c.p.owner.typ[0] != nil: localError(c.config, n.info, errGenerated, "yield statement must yield a value") +proc considerQuotedIdentOrDot(c: PContext, n: PNode, origin: PNode = nil): PIdent = + if n.kind == nkDotExpr: + let a = considerQuotedIdentOrDot(c, n[0], origin).s + let b = considerQuotedIdentOrDot(c, n[1], origin).s + var s = newStringOfCap(a.len + b.len + 1) + s.add(a) + s.add('.') + s.add(b) + result = getIdent(c.cache, s) + else: + result = considerQuotedIdent(c, n, origin) + proc semDefined(c: PContext, n: PNode): PNode = checkSonsLen(n, 2, c.config) # we replace this node by a 'true' or 'false' node: result = newIntNode(nkIntLit, 0) - result.intVal = ord isDefined(c.config, considerQuotedIdent(c, n[1], n).s) + result.intVal = ord isDefined(c.config, considerQuotedIdentOrDot(c, n[1], n).s) result.info = n.info result.typ = getSysType(c.graph, n.info, tyBool) |