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

Playground @LOCATION and @FILE_LINE interpolation problems #23554

Open
jorgeluismireles opened this issue Jan 22, 2025 · 6 comments
Open

Playground @LOCATION and @FILE_LINE interpolation problems #23554

jorgeluismireles opened this issue Jan 22, 2025 · 6 comments
Labels
Bug This tag is applied to issues which reports bugs. OS: Playground Bugs/feature requests, that are specific to play.vlang.io.

Comments

@jorgeluismireles
Copy link

jorgeluismireles commented Jan 22, 2025

Describe the bug

When you println interpolated values @LOCATION or @FILE_LINE the compiler fails under two conditions:

  • The values are the first thing to print
  • Only in the playground

Reproduction Steps

Run in playground this https://play.vlang.io/p/1c01efec08 :

fn main() {
	ok()
	workaround()
	fail_1()
	fail_2()
}

fn ok() {
	println('${@VROOT}')
	println('${@VMODROOT}')
	println('${@VEXEROOT}')
	println('${@FN}')
	println('${@METHOD}')
	println('${@MOD}')
	println('${@STRUCT}')
	println('${@VEXE}')
	println('${@FILE}')
	println('${@LINE}')
	println('${@COLUMN}')
	println('${@VHASH}')
	println('${@VCURRENTHASH}')
	println('${@BUILD_DATE}')
	println('${@BUILD_TIME}')
	println('${@BUILD_TIMESTAMP}')
}

fn workaround() {
	println('X ${@LOCATION}')
	println('X ${@FILE_LINE}')
}

fn fail_1() {
	println('${@LOCATION}')
}

fn fail_2() {
	println('${@FILE_LINE}')
}

Explanation

  • ok function works ok for all the variables within starting in every interpolation.
  • workaround function works because I started with an X before @LOCATION and @FILE_LINE, only this way worked.
  • fail_1 and fail_2 functions fail, anyone.

Expected Behavior

Some boring list with values (all the recommended by the compiler...)

Current Behavior

OK (0.298 sec real, 0.298 sec wall)
Can't run code. t[3] is undefined
Please try again.

Possible Solution

Workaround is to comment both fail_1 and fail_2 calls in main, even is not necessary to comment the functions.

fn main() {
	ok()
	workaround()
	//fail_1()
	//fail_2()
}

Or in other words, do what workaround function don't start the print interpolation with the values.

Additional Information/Context

Found while inspecting this issue: #23550

V version

V 0.4.9 6b0c272

Environment details (OS name and version, etc.)

Playground only.

For me only failed in playground. I ran the code in ubuntu and worked for gcc, clang and tcc so maybe the problem is specific to the plaground platform.

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.

@jorgeluismireles jorgeluismireles added the Bug This tag is applied to issues which reports bugs. label Jan 22, 2025
Copy link

Connected to Huly®: V_0.6-21982

@spytheman
Copy link
Member

That is a problem with the JS frontend of the playground, not a compiler one:
The compiler and the program ran successfully, but later, the returned response failed to be processed:
Image

@spytheman
Copy link
Member

A simpler reproduction is with just:
println('code.v:2')

which also causes:

Image

@spytheman
Copy link
Member

spytheman commented Jan 23, 2025

I think that the JS frontend of the playground treats code.v: at the start of a line, as a pattern for errors, and tries to retrieve the error value after that, which fails, because the line ends.

@spytheman
Copy link
Member

spytheman commented Jan 23, 2025

@LOCATION and @FILE_LINE are involved only indirectly, because they also produce code.v: (the name of the file on the playground, that is compiled on each click of the Run button).

@jorgeluismireles
Copy link
Author

println('code.v:2')

At least as println('code.v:') fails, though dump('code.v:') works.

@felipensp felipensp added the OS: Playground Bugs/feature requests, that are specific to play.vlang.io. label Jan 23, 2025
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. OS: Playground Bugs/feature requests, that are specific to play.vlang.io.
Projects
None yet
Development

No branches or pull requests

3 participants