Can't return a string #9

Closed
opened 2025-08-14 13:18:58 +00:00 by zupa · 4 comments

Code:

import io

main() {
	s := getStr()
	io.write(s)
}

getStr() -> string {
	return "hi\n"
}

Error:

tests/memory.q:9:9

    return "hi\n"
           ┬
           ╰─ Unused value '"hi\n"'

/home/zupa/p/q/src/git.urbach.dev/cli/q/src/core/removeDeadCode.go:39
/home/zupa/p/q/src/git.urbach.dev/cli/q/src/core/Compile.go:23
/home/zupa/p/q/src/git.urbach.dev/cli/q/src/compiler/Compile.go:45
/home/zupa/p/q/src/git.urbach.dev/cli/q/src/compiler/parallel.go:23
/home/zupa/p/q/src/git.urbach.dev/cli/q/src/compiler/parallel.go:21
Code: ``` import io main() { s := getStr() io.write(s) } getStr() -> string { return "hi\n" } ``` Error: ``` tests/memory.q:9:9 return "hi\n" ┬ ╰─ Unused value '"hi\n"' /home/zupa/p/q/src/git.urbach.dev/cli/q/src/core/removeDeadCode.go:39 /home/zupa/p/q/src/git.urbach.dev/cli/q/src/core/Compile.go:23 /home/zupa/p/q/src/git.urbach.dev/cli/q/src/compiler/Compile.go:45 /home/zupa/p/q/src/git.urbach.dev/cli/q/src/compiler/parallel.go:23 /home/zupa/p/q/src/git.urbach.dev/cli/q/src/compiler/parallel.go:21 ```
ed self-assigned this 2025-08-14 13:41:24 +00:00
Owner

A string is a two-register value (aka tuple/struct) and multi return values aren't implemented yet.

Nonetheless I'll classify this as a bug (high priority) because we need this to work for the upcoming memory instructions.

A string is a two-register value (aka tuple/struct) and multi return values aren't implemented yet. Nonetheless I'll classify this as a bug (high priority) because we need this to work for the upcoming memory instructions.
Author

Ah I see, now I understand why I couldn't get string return values to work in the past days.

Ah I see, now I understand why I couldn't get string return values to work in the past days.
Owner

Fixed in cli/q@1e72e444b3.

Test is return-string.q.

Fixed in https://git.urbach.dev/cli/q/commit/1e72e444b314061b9312b34ea3e06a8ade005162. Test is [return-string.q](https://git.urbach.dev/cli/q/src/branch/main/tests/return-string.q).
ed changed title from Unused value (unexpected) to Can't return a string 2025-08-17 12:18:00 +00:00
ed added spent time 2025-08-17 12:18:52 +00:00
4 hours
Author

Great, thx!

Great, thx!
zupa closed this issue 2025-08-17 13:47:35 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Total time spent: 4 hours
ed
4 hours
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cli/q#9
No description provided.