Closed juancarlospaco closed 3 days ago
!nim c
func f(a: string) = discard
template t(a: string) = f(a = a)
t(a = "BUG")
0 (0 bytes)
```cpp
```
2024-11-09T00:47:03
2024-11-09T00:47:04
0 (0 bytes)
```cpp
```
2024-11-09T00:47:07
2024-11-09T00:47:08
0 (0 bytes)
```cpp
```
2024-11-09T00:47:11
2024-11-09T00:47:11
0 (0 bytes)
```cpp
```
2024-11-09T00:47:15
2024-11-09T00:47:15
0 (0 bytes)
```cpp
```
2024-11-09T00:47:18
2024-11-09T00:47:19
0 (0 bytes)
```cpp
```
2024-11-09T00:47:22
2024-11-09T00:47:22
0 (0 bytes)
```cpp
```
2024-11-09T00:47:25
2024-11-09T00:47:25
0 (0 bytes)
```cpp
```
2024-11-09T00:47:28
2024-11-09T00:47:28
11.4.0
14.0.0
20.4
2024-11-09T00:46:34Z
1
nim c --run -d:nimDebug -d:nimDebugDlOpen -d:ssl -d:nimDisableCertificateValidation --forceBuild:on --colors:off --verbosity:0 --hints:off --lineTrace:off --nimcache:/home/runner/work/Nim/Nim --out:/home/runner/work/Nim/Nim/temp /home/runner/work/Nim/Nim/temp.nim
:robot: Bug found in 27 mins
bisecting 8
commits at 0
commits per second
This is expected given that any usage of an identifier expands to the parameter.
Even on an identifier name left-hand side? 🤔
In which scenarios having f( "value" = "value" )
is a reasonable expansion?
I think should be possible to make the compiler at least produce a warning...
Implementing a template that invokes a macro where you actually want "a" = "b"
.
Description
Templates expand to
rvalue=rvalue
(right-hand side literal values) arguments when the template argument and the function argument have the same name.Same happens inside a
main()
function.Alternative can be change identifier names like
body = bodi
in arguments, but its weird and don't change the fact that the compiler is using literal values as identifier names in expansions.Nim Version
2.2.1
Current Output
Expected Output
Compile Ok, or give some kind of ambiguous identifier error?
Known Workarounds
Change the name of the arguments, but you have to edit the whole code.
I found this because I have templates that use
body=body
for HTTP code, and theexpandMacros
shows code likef( "BUG" = "BUG" )
, but should be likef( body = "BUG" )
, then complainsError: identifier expected, but found '"BUG"'
.Additional Information
See Bisect below...