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

[BUG] Warning when using args as the name of a function argument #631

Open
lens0021 opened this issue Dec 12, 2024 · 6 comments
Open

[BUG] Warning when using args as the name of a function argument #631

lens0021 opened this issue Dec 12, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@lens0021
Copy link
Contributor

lens0021 commented Dec 12, 2024

Describe the bug
If you use args as the name of an argument, a warning would be printed when running the bash script.

To Reproduce

$ amber-master eval 'fun fun1(args: [Text]): Null {echo "Hello"} main(args) {fun1(args)}'
main: line 6: fun1__0_v0: args: readonly variable
main: line 6: local: args: readonly variable
Hello

Expected behavior
No warning printed. Like when you use args1 as the name, then:

$ amber-master eval 'fun fun1(args1: [Text]): Null {echo "Hello"} main(args) {fun1(args)}'
Hello

Additional context
echo 'fun fun1(args: [Text]): Null {echo "Hello"} main(args) {fun1(args)}' | amber-master build -:

#!/usr/bin/env bash
# Written in [Amber](https://amber-lang.com/)
# version: 0.3.5-alpha
# date: 2024-12-12 23:51:55
fun1__0_v0() {
    local args=("${!1}")
    echo "Hello"
}
declare -r args=("$0" "$@")
fun1__0_v0 args[@]
__AF_fun10_v0__1_57="$__AF_fun10_v0"
echo "$__AF_fun10_v0__1_57" >/dev/null 2>&1

It seems args is declared twice.

@lens0021 lens0021 added the bug Something isn't working label Dec 12, 2024
@github-project-automation github-project-automation bot moved this to 🆕 New in Amber Project Dec 12, 2024
@lens0021
Copy link
Contributor Author

Therefore,

pub fun printf(format: Text, args: [Text] = [""]): Null {
prints the warning. Isn't it happened to anyone than me?

@Mte90
Copy link
Member

Mte90 commented Dec 12, 2024

I don't know if #630 will fix it

@hdwalters
Copy link
Contributor

Also:

$ echo -e 'fun fun1(args: [Text]): Null {echo "Hello"}\n main(args) {fun1(args)}' | amber-master build - | bash

Wow, that's a convoluted way of running an Amber fragment. Wouldn't it be simpler to use amber eval?

@lens0021
Copy link
Contributor Author

I'm not yet familiar with the new sub commands enough 😅

@lens0021
Copy link
Contributor Author

(*edited)

@hdwalters
Copy link
Contributor

Looks like we just need to mangle the variable name args with a global variable ID, so we create something like:

declare -r __args_0=("$0" "$@")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants