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

✨ Subscript syntax should work for any expression that is of type array #211

Open
CymDeveloppement opened this issue Jun 18, 2024 · 3 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request syntax

Comments

@CymDeveloppement
Copy link
Member

Hi,
we have many project of bash script, and i think amber is very cool

when i use the function directly as array, i have a parser error :
But i seem is incorrect.

fun command_exist(command: Text):Bool {
	echo command
	return true
}

command_exist(split("foo bar", " ")[0])

Parser :

 ERROR 
Variable 'command_exist' does not exist
at test.ab:10:2


9 | 	
10| 	command_exist(split("foo bar", " ")[0])
11| 

and if i store function result in variable :

let splitText = split("foo bar", " ")[0]
command_exist(splitText)
ERROR 
1st argument 'command' of function 'command_exist' expects type 'Text', but '[Text]' was given
at test.ab:10:2


9 | 	let splitText = split("foo bar", " ")[0]
10| 	command_exist(splitText)

thx

@Ph0enixKM
Copy link
Member

I think that the [0] doesn't work on expressions as of right now. You'd have to assign it to a variable first. This is something that has to be improved soon. Thanks for the issue! I'll add a warning in the docs so that people can see this

@CymDeveloppement
Copy link
Member Author

for a more comprehensive code, i created a function and it works great.

fun array_value(array, index) {
	return array[index]
}
main {
	let splitText = array_value(split("foo bar", " "), 0)
	command_exist(splitText)
        command_exist(array_value(split("foobar", " "), 0))
}

@Ph0enixKM Ph0enixKM changed the title Error when function used as array directly ✨ Subscript syntax should work for any expression that is of type array Jun 18, 2024
@Ph0enixKM
Copy link
Member

Thank you for creating this issue @CymDeveloppement

@Mte90 Mte90 added documentation Improvements or additions to documentation enhancement New feature or request labels Jun 24, 2024
@Mte90 Mte90 added the syntax label Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request syntax
Projects
None yet
Development

No branches or pull requests

3 participants