c-blake / cligen

Nim library to infer/generate command-line-interfaces / option / argument parsing; Docs at
https://c-blake.github.io/cligen/
ISC License
506 stars 24 forks source link

Cannot use `delete` as the function name #39

Closed kdheepak closed 5 years ago

kdheepak commented 5 years ago

If I create a package using nimble init called commandlinenim and save the following in ./src/commandlinenim.nim,

import strformat

proc delete(file: string): int =
    echo fmt"Deleting {file}"

when isMainModule:
    import cligen
    dispatch(delete)

and change the nimble file to point to cligen#head, and run the following from the root directory,

nimble build

I get the following error

  Verifying dependencies for commandlinenim@0.1.0
      Info: Dependency on cligen@#head already satisfied
  Verifying dependencies for cligen@#head
   Building commandlinenim/commandlinenim using c backend
       Tip: 6 messages have been suppressed, use --verbose to show them.
     Error: nimble.nim(1106)         nimble
        ... nimble.nim(1064)         doAction
        ... nimble.nim(510)          build
        ... nimble.nim(245)          buildFromDir
        ... Build failed for package: commandlinenim
        ... Details:
        ... nimble.nim(1106)         nimble
        ... nimble.nim(1064)         doAction
        ... nimble.nim(510)          build
        ... nimble.nim(237)          buildFromDir
        ... tools.nim(37)            doCmd
        ... Execution failed with exit code 1
        ... Command: "/Users/$USER/.nimble/bin/nim" c --noBabelPath --path:"/Users/$USER/.nimble/pkgs/cligen-#head"  -o:"/Users/$USER/GitRepos/commandlinenim/commandlinenim" "/Users/$USER/GitRepos/commandlinenim/src/commandlinenim.nim"
        ... Output: Hint: used config file '/Users/$USER/.choosenim/toolchains/nim-0.19.0/config/nim.cfg' [Conf]
        ... Hint: system [Processing]
        ... Hint: commandlinenim [Processing]
        ... Hint: strformat [Processing]
        ... Hint: macros [Processing]
        ... Hint: parseutils [Processing]
        ... Hint: unicode [Processing]
        ... Hint: strutils [Processing]
        ... Hint: math [Processing]
        ... Hint: bitops [Processing]
        ... Hint: algorithm [Processing]
        ... Hint: cligen [Processing]
        ... Hint: tables [Processing]
        ... Hint: hashes [Processing]
        ... Hint: parseopt3 [Processing]
        ... Hint: os [Processing]
        ... Hint: times [Processing]
        ... Hint: options [Processing]
        ... Hint: typetraits [Processing]
        ... Hint: posix [Processing]
        ... Hint: ospaths [Processing]
        ... Hint: argcvt [Processing]
        ... Hint: sets [Processing]
        ... Hint: textUt [Processing]
        ... Hint: terminal [Processing]
        ... Hint: colors [Processing]
        ... Hint: termios [Processing]
        ... commandlinenim.nim(8, 13) template/generic instantiation from here
        ... ../../../.choosenim/toolchains/nim-0.19.0/lib/system.nim(1541, 28) Error: undeclared identifier: 'T'

It appears that I cannot use delete as a function name.

c-blake commented 5 years ago

Well, if you look at system.nim line 1541 that is also delete. So, the problem is the wrong symbol is selected. As mentioned in DETAILS.md rule 3, generic procs are not supported as dispatch targets. In your case, you aren't defining a new generic proc, but you are creating an overload with the same name as an existing generic proc. I am not sure that can be worked around in any way other than changing your name, e.g., remove instead of delete. To fix this problem in general, we need a way to guide getImpl to the right symbol.

kdheepak commented 5 years ago

I think there is a thing in Nim where you can use backticks to escape default, so I tried to use `delete` instead of delete, I couldn't figure it out. I switched to remove instead.