mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-17 00:24:16 +00:00
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:
@@ -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
|
||||
|
||||
4
tests/stdlib/mstrscans_undecl_scanf.nim
Normal file
4
tests/stdlib/mstrscans_undecl_scanf.nim
Normal file
@@ -0,0 +1,4 @@
|
||||
import std/strscans
|
||||
|
||||
proc scan*[T](s: string): (bool, string) =
|
||||
s.scanTuple("$+")
|
||||
3
tests/stdlib/tstrscans_undecl_scanf.nim
Normal file
3
tests/stdlib/tstrscans_undecl_scanf.nim
Normal file
@@ -0,0 +1,3 @@
|
||||
import std/assertions
|
||||
import ./mstrscans_undecl_scanf
|
||||
doAssert scan[int]("foo") == (true, "foo")
|
||||
Reference in New Issue
Block a user