Files
Nim/lib/std/private/underscored_calls.nim
ee7 629b22e3d5 styleCheck: Fix error for sugar and std/with (#16176)
With this commit, we no longer see an error if we pass
`--styleCheck:error` when compiling a file that contains `import sugar`
or `import std/with`.

The problem was that those modules (and only those modules) import
`std/private/underscored_calls`, which contained a styleCheck issue:
its spelling of `nnkArgList` didn't match the `nnkArglist` spelling in
`macros.nim`.

This commit fixes the issue by renaming `nnkArgList` to `nnkArglist`
repo-wide. The other way around would be a breaking change for code that
used `nnkArglist` and `--styleCheck:error`.

Fixes: #16174
2020-12-02 20:48:16 +01:00

49 lines
1.2 KiB
Nim

#
#
# Nim's Runtime Library
# (c) Copyright 2020 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## This is an internal helper module. Do not use.
import macros
proc underscoredCall(n, arg0: NimNode): NimNode =
proc underscorePos(n: NimNode): int =
for i in 1 ..< n.len:
if n[i].eqIdent("_"): return i
return 0
if n.kind in nnkCallKinds:
result = copyNimNode(n)
result.add n[0]
let u = underscorePos(n)
for i in 1..u-1: result.add n[i]
result.add arg0
for i in u+1..n.len-1: result.add n[i]
elif n.kind in {nnkAsgn, nnkExprEqExpr}:
var field = n[0]
if n[0].kind == nnkDotExpr and n[0][0].eqIdent("_"):
# handle _.field = ...
field = n[0][1]
result = newDotExpr(arg0, field).newAssignment n[1]
else:
# handle e.g. 'x.dup(sort)'
result = newNimNode(nnkCall, n)
result.add n
result.add arg0
proc underscoredCalls*(result, calls, arg0: NimNode) =
expectKind calls, {nnkArglist, nnkStmtList, nnkStmtListExpr}
for call in calls:
if call.kind in {nnkStmtList, nnkStmtListExpr}:
underscoredCalls(result, call, arg0)
else:
result.add underscoredCall(call, arg0)