Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a closure called instantly with an or block fails to compile #21165

Open
bramvbilsen opened this issue Apr 1, 2024 · 0 comments
Open

a closure called instantly with an or block fails to compile #21165

bramvbilsen opened this issue Apr 1, 2024 · 0 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@bramvbilsen
Copy link
Contributor

bramvbilsen commented Apr 1, 2024

Describe the bug

Trying to inline a function with an Option return which is invoked immediately results in a compilation error when using an or block.

Reproduction Steps

The following code results in the described bug behavior:

server_script_path := fn [tmp_wd] () !string {
    server_script_embedded_file := $embed_file('./src/server.sh')
    path := os.join_path(tmp_wd, 'server.sh')
    os.write_file(path, server_script_embedded_file.to_string())!
    return path
}() or { panic(err) }

Expected Behavior

I would expect this to compile without issue.

Current Behavior

Does not compile:

/tmp/v_501/core_v.01HTDW22W7WKSQ5Q8XPN9GNMEG.tmp.c:23570:9: error: initializing 'string' (aka 'struct string') with an expression of incompatible type '_result_string (*)()' (aka 'struct _result_string (*)()')
        string server_script_path =
               ^
/tmp/v_501/core_v.01HTDW22W7WKSQ5Q8XPN9GNMEG.tmp.c:23571:5: error: expected ';' at end of declaration
        _t5     _result_string _t6 = __closure_create(anon_fn_143c1662f75e5a6c___result_string_1704, (struct _V_anon_fn_143c1662f75e5a6c___result_string_1704_Ctx*) memdup_uncollectable(&(struct _V_anon_fn_143c1662f75e5a6c___result_string_1704_Ctx){.tmp_wd = tmp_wd,
           ^
           ;
/tmp/v_501/core_v.01HTDW22W7WKSQ5Q8XPN9GNMEG.tmp.c:23572:74: error: called object type 'void *' is not a function or function pointer
        }, sizeof(struct _V_anon_fn_143c1662f75e5a6c___result_string_1704_Ctx)))();

The following does however compiler:

server_script_path := fn [tmp_wd] () string {
	server_script_embedded_file := $embed_file('./src/server.sh')
	path := os.join_path(tmp_wd, 'server.sh')
	os.write_file(path, server_script_embedded_file.to_string()) or { panic(err) }
	return path
}()

Possible Solution

No response

Additional Information/Context

No response

V version

0.4.5 e6b43a1

Environment details (OS name and version, etc.)

V full version: V 0.4.5 365bd18.e6b43a1
OS: macos, macOS, 14.4, 23E214
Processor: 10 cpus, 64bit, little endian, Apple M1 Max

getwd: /X/Y/Z
vexe: /X/Y/Z/v/v
vexe mtime: 2024-03-20 20:08:31

vroot: OK, value: /Users/X/DevTools/v
VMODULES: OK, value: /Users/X/.vmodules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.44.0
Git vroot status: weekly.2024.12-13-ge6b43a16 (82 commit(s) behind V master)
.git/config present: true

CC version: Apple clang version 15.0.0 (clang-1500.3.9.4)
thirdparty/tcc status: thirdparty-macos-arm64 5c1d002f

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.

@bramvbilsen bramvbilsen added the Bug This tag is applied to issues which reports bugs. label Apr 1, 2024
@spytheman spytheman changed the title Inline function called instantly with an or block fails to compile a closure called instantly with an or block fails to compile Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

1 participant