vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io
MIT License
35.66k stars 2.15k forks source link

Compiler error when trying to convey a variadic argument set #22049

Open dadooda opened 4 weeks ago

dadooda commented 4 weeks ago

Describe the bug

As shown by the demo file below.

Reproduction Steps

Trying compile this:

//
// Compiler error demo.
//

import os

fn do_join(args ...string) string {
  return os.join_path(...args)
}

, I get this:

C error found. It should never happen, when compiling pure V code.
…
======== Output of the C Compiler (/opt/vlang-0.4.7/thirdparty/tcc/tcc.exe) ========
/tmp/v_1000/convey_variadic.01J5AN421S295DVWKTHD7Y9PG5.tmp.c:18777: error: ',' expected (got "args")
====================================================================================
======== Output of the C Compiler (cc) ========
/tmp/v_1000/convey_variadic.01J5AN421S295DVWKTHD7Y9PG5.tmp.c: In function ‘main__do_join’:
/tmp/v_1000/convey_variadic.01J5AN421S295DVWKTHD7Y9PG5.tmp.c:18777:93: error: expected ‘)’ before ‘args’
  string _t1 = os__join_path(*(string*)array_get(args, 0), *(Array_string*)array_get(args, 1)args);
                                                                                             ^~~~
===============================================

Expected Behavior

Proper compilation.

Current Behavior

Compilation failure.

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.7 7baff15

Environment details (OS name and version, etc.)

Ubuntu 18 under WSL.

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

spytheman commented 3 weeks ago

Given that pub fn join_path(base string, dirs ...string) string {, I think that os.join_path(...args) should be a checker error (the first argument base, is a string).

spytheman commented 3 weeks ago

This for example works as it should (with an explicit string literal used as the first argument):

import os

fn do_join(args ...string) string {
  return os.join_path('abc', ...args)
}

dump( do_join('xx', 'yy') )
dadooda commented 3 weeks ago

Delyan,

I think that os.join_path(...args) should be a checker error.

Sounds quite reasonable.