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

os.signal_opt with closure in callback does not compile #21819

Closed
mike-ward opened this issue Jul 7, 2024 · 3 comments · Fixed by #21908
Closed

os.signal_opt with closure in callback does not compile #21819

mike-ward opened this issue Jul 7, 2024 · 3 comments · Fixed by #21908
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones).

Comments

@mike-ward
Copy link
Contributor

mike-ward commented Jul 7, 2024

Describe the bug

Calling os.signal_opt with closure in callback does not compile stating it is not expecting a comma after the first argument.

Reproduction Steps

fn set_auto_wrap(options Options) {
	if options.no_wrap {
		wrap_off := '\e[?7h'
		wrap_reset := '\e[?7l'

		print(wrap_off) 

		at_exit(fn [wrap_reset] () {
			print(wrap_reset)
		}) or {}

		os.signal_opt(os.Signal.int, fn [wrap_reset] (sig os.Signal) {
			print(wrap_reset)
			exit(0)
		}) or {}
	}
}

Expected Behavior

Should compile

Current Behavior

Mikes-Air➜  lsv : main ✘ :✹ ᐅ  v run .
lsv.v:56:30: error: unexpected token `,`, expecting `(`
   54 |         }) or {}
   55 | 
   56 |         os.signal_opt(os.Signal.int, fn [wrap_reset] (sig os.Signal) {
      |                                    ^
   57 |             print(wrap_reset)
   58 |             exit(0)
Mikes-Air➜  lsv : main ✘ :✹ ᐅ  

Possible Solution

Changing the code as follows compiles

fn set_auto_wrap(options Options) {
	if options.no_wrap {
		wrap_off := '\e[?7h'
		wrap_reset := '\e[?7l'

		print(wrap_off)

		at_exit(fn [wrap_reset] () {
			print(wrap_reset)
		}) or {}

		os.signal_opt(os.Signal.int, fn (sig os.Signal) {
			print('\e[?7l')
			exit(0)
		}) or {}
	}
}

Additional Information/Context

No response

V version

V 0.4.6 f6de36d

Environment details (OS name and version, etc.)

V full version: V 0.4.6 8215f21.f6de36d
OS: macos, macOS, 14.5, 23F79
Processor: 8 cpus, 64bit, little endian, Apple M2

getwd: /Users/mike/Documents/github/lsv/lsv
vexe: /Users/mike/Documents/github/v/v
vexe mtime: 2024-07-07 15:50:01

vroot: OK, value: /Users/mike/Documents/github/v
VMODULES: OK, value: /Users/mike/.vmodules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.45.2
Git vroot status: weekly.2024.27-29-gf6de36db
.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.

@mike-ward mike-ward added the Bug This tag is applied to issues which reports bugs. label Jul 7, 2024
@spytheman
Copy link
Member

spytheman commented Jul 10, 2024

A smaller complete reproduction is:

import os

x := '\e[?7l'
os.signal_opt(os.Signal.int, fn [x] (sig os.Signal) {
	print(x)
	exit(0)
}) or {}

Using os.signal_opt(.int instead, fixes it, so it is most likely due to a call expression argument parser lookup problem.

@spytheman spytheman added Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones). Status: Confirmed This bug has been confirmed to be valid by a contributor. labels Jul 10, 2024
@manosriram
Copy link

@spytheman can i try this one?

@spytheman
Copy link
Member

@spytheman can i try this one?

Try it in what sense?
If you mean to make a PR for solving it, go ahead.

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. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Parser Bugs/feature requests, that are related to the V parser or syntax (*not* semantic ones).
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants