V version:
V 0.1.25 5142747
gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)
OS: Win10
What did you do?
compile this trivial source file:
fn main() {
log('nox')
}
fn log(line string) {
println(line)
}
What did you expect to see?
no error.
Note: older version of v compiles without errors
V 0.1.25 d499116 (approx 2020-02-15)
What did you see instead?
c:\dev_alt\vlang\test>v -cg trivial_error.v
C:\Users\alisurbo\AppData\Local\Temp\v\trivial_error.tmp.c:159: warning: "UNICODE" redefined
#define UNICODE
<command-line>: note: this is the location of the previous definition
C:\Users\alisurbo\AppData\Local\Temp\v\trivial_error.tmp.c: In function 'print':
C:\Users\alisurbo\AppData\Local\Temp\v\trivial_error.tmp.c:1631:58: warning: passing argument 4 of 'WriteConsoleW' from incompatible pointer type [-Wincompatible-pointer-types]
WriteConsole ( output_handle , wide_str , wide_len , & bytes_written , 0 ) ;
^~~~~~~~~~~~~~~
In file included from c:/dev_alt/mingw64/x86_64-w64-mingw32/include/windows.h:74,
from C:\Users\alisurbo\AppData\Local\Temp\v\trivial_error.tmp.c:160:
c:/dev_alt/mingw64/x86_64-w64-mingw32/include/wincon.h:260:122: note: expected 'LPDWORD' {aka 'long unsigned int *'} but argument is of type 'int *'
WINBASEAPI WINBOOL WINAPI WriteConsoleW(HANDLE hConsoleOutput,CONST VOID *lpBuffer,DWORD nNumberOfCharsToWrite,LPDWORD lpNumberOfCharsWritten,LPVOID lpReserved);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
C:\Users\alisurbo\AppData\Local\Temp\v\trivial_error.tmp.c:1634:58: warning: passing argument 4 of 'WriteFile' from incompatible pointer type [-Wincompatible-pointer-types]
WriteFile ( output_handle , (char*) s .str , s .len , & bytes_written , 0 ) ;
^~~~~~~~~~~~~~~
In file included from c:/dev_alt/mingw64/x86_64-w64-mingw32/include/winbase.h:18,
from c:/dev_alt/mingw64/x86_64-w64-mingw32/include/windows.h:70,
from C:\Users\alisurbo\AppData\Local\Temp\v\trivial_error.tmp.c:160:
c:/dev_alt/mingw64/x86_64-w64-mingw32/include/fileapi.h:175:109: note: expected 'LPDWORD' {aka 'long unsigned int *'} but argument is of type 'int *'
WINBASEAPI WINBOOL WINAPI WriteFile (HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
C:\Users\alisurbo\AppData\Local\Temp\v\trivial_error.tmp.c: In function 'strconv__atof64':
C:\Users\alisurbo\AppData\Local\Temp\v\trivial_error.tmp.c:5031:65: warning: initialized field overwritten [-Woverride-init]
strconv__Float64u res= (strconv__Float64u) { .f = 0.0 , .u = ((u64)( 0 ) ) } ;
^
C:\Users\alisurbo\AppData\Local\Temp\v\trivial_error.tmp.c:5031:65: note: (near initialization for '(anonymous).u')
C:\Users\alisurbo\AppData\Local\Temp\v\trivial_error.tmp.c: In function 'strconv_dot_ftoa__f32_to_str':
C:\Users\alisurbo\AppData\Local\Temp\v\trivial_error.tmp.c:5999:84: warning: initialized field overwritten [-Woverride-init]
strconv_dot_ftoa__Uf32 u1= (strconv_dot_ftoa__Uf32) { .f = ((f32)( 0 ) ) , .u = 0 } ;
^
C:\Users\alisurbo\AppData\Local\Temp\v\trivial_error.tmp.c:5999:84: note: (near initialization for '(anonymous).u')
C:\Users\alisurbo\AppData\Local\Temp\v\trivial_error.tmp.c: In function 'strconv_dot_ftoa__f64_to_str':
C:\Users\alisurbo\AppData\Local\Temp\v\trivial_error.tmp.c:6262:84: warning: initialized field overwritten [-Woverride-init]
strconv_dot_ftoa__Uf64 u1= (strconv_dot_ftoa__Uf64) { .f = ((f64)( 0 ) ) , .u = 0 } ;
^
C:\Users\alisurbo\AppData\Local\Temp\v\trivial_error.tmp.c:6262:84: note: (near initialization for '(anonymous).u')
C:\Users\alisurbo\AppData\Local\Temp\v\trivial_error.tmp.c: In function 'main__main':
C:\Users\alisurbo\AppData\Local\Temp\v\trivial_error.tmp.c:6612:8: error: incompatible type for argument 1 of 'log'
log ( "nox" ) ;
^~~~~
In file included from C:\Users\alisurbo\AppData\Local\Temp\v\trivial_error.tmp.c:369:
c:/dev_alt/mingw64/x86_64-w64-mingw32/include/math.h:194:29: note: expected 'double' but argument is of type 'char *'
double __cdecl log(double _X);
~~~~~~~^~
V error:
==================
C error. This should never happen.
V compiler version: V 0.1.25 5142747
Host OS: Windows
Target OS: Windows
If you were not working with C interop and are not sure about what's happening,
please put the whole output in a pastebin and contact us through the following ways with a link to the pastebin:
- Raise an issue on GitHub: https://github.com/vlang/v/issues/new/choose
- Ask a question in #help on Discord: https://discord.gg/vlang
log is defined in C's math.h, just use different name for now
This library-defined function issue can be overcomed by using main.log(...) instead of log(...) in code.
math library seems to be imported by default (not necessary to use "import math" and math.log(...) in code ?).
Code below shows how to use both "local" log function and "reserved" math library log function.
module main // This line can be commented
fn main() {
main.log('nox') // local log function
println(log(10)) // library math log function
}
fn log(line string) {
println(line)
}
this bug is not fixed. the "name-clash" is a systematic problem.
so why close it without further comment?
I agree it should be open until it's possible to use log for anything.
this bug returned with v2 :-/ (cannot "reopen")
note: writing a unit test for each reported bug improves software quality
Most helpful comment
logis defined in C'smath.h, just use different name for now