Fix scanTuple undeclared identifier 'scanf' (#24759)

Without this fix, trying to use `scanTuple` in a generic proc imported
from a different module fails to compile (`undeclared identifier:
'scanf'`):

```nim
# module.nim
import std/strscans

proc scan*[T](s: string): (bool, string) =
  s.scanTuple("$+")
```

```nim
# main.nim
import ./module

echo scan[int]("foo")
```

Workaround is to `export scanf` in `module.nim` or `import std/strscans`
in `main.nim`.

(cherry picked from commit f8294ce06e)
This commit is contained in:
Laylie
2025-03-10 22:47:03 +08:00
committed by narimiran
parent 6651c40ba0
commit cd9c47140e
3 changed files with 8 additions and 1 deletions

View File

@@ -512,7 +512,7 @@ macro scanTuple*(input: untyped; pattern: static[string]; matcherTypes: varargs[
inc userMatches
else: discard
inc p
result.add nnkTupleConstr.newTree(newCall(ident("scanf"), input, newStrLitNode(pattern)))
result.add nnkTupleConstr.newTree(newCall(bindSym("scanf"), input, newStrLitNode(pattern)))
for arg in arguments:
result[^1][0].add arg
result[^1].add arg

View File

@@ -0,0 +1,4 @@
import std/strscans
proc scan*[T](s: string): (bool, string) =
s.scanTuple("$+")

View File

@@ -0,0 +1,3 @@
import std/assertions
import ./mstrscans_undecl_scanf
doAssert scan[int]("foo") == (true, "foo")