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

feat(test): for variables, #433 #553

Merged
merged 8 commits into from
Nov 6, 2024
Merged

feat(test): for variables, #433 #553

merged 8 commits into from
Nov 6, 2024

Conversation

Mte90
Copy link
Member

@Mte90 Mte90 commented Oct 28, 2024

As per #433

I am not sure if I added all of them, in the case of another scopethere is an error if the variable is not defined and it is part of the errors we are not checking right now (another ticket).

@Mte90 Mte90 requested review from hdwalters, Ph0enixKM and b1ek October 28, 2024 11:47
@Ph0enixKM
Copy link
Member

@Mte90 please add all shorthand operators like +=, -=, *=, /=, %= as well as using variables by reference ref

@Mte90
Copy link
Member Author

Mte90 commented Oct 28, 2024

So like let var += 1?

@Ph0enixKM
Copy link
Member

Yep, and do all that again for variables passed by reference:

fun foo(ref var) {
    var = 1
    var += 2
    // ...
}

@Mte90
Copy link
Member Author

Mte90 commented Oct 28, 2024

Added :-)

b1ek

This comment was marked as resolved.

@Mte90

This comment was marked as resolved.

Copy link
Member

@Ph0enixKM Ph0enixKM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Mte90 the ref keyword is used to access variables by reference through function arguments. I feel like you misunderstood the functionality it provides.

If we use ref we can mutate certain value from the external environment. Here's an example of a function using reference and one that is not using references:

Reference

fun foo(ref arg) {
    arg = "foo"
}


let my_var = "test"
foo(my_var)
echo my_var // Outputs: "foo"

No reference

fun foo(arg) {
    arg = "foo"
}


let my_var = "test"
foo(my_var)
echo my_var // Outputs: "test"

src/tests/validity/variable_ref_another_scope.ab Outdated Show resolved Hide resolved
src/tests/validity/variable_ref_global.ab Outdated Show resolved Hide resolved
src/tests/validity/variable_ref_operators.ab Outdated Show resolved Hide resolved
src/tests/validity/variable_ref_redefinition.ab Outdated Show resolved Hide resolved
Mte90 and others added 2 commits November 4, 2024 11:15
Co-authored-by: Phoenix Himself <pkaras.it@gmail.com>
@Mte90 Mte90 requested a review from Ph0enixKM November 4, 2024 10:59
@Mte90
Copy link
Member Author

Mte90 commented Nov 4, 2024

Updated, about ref I didn't knew about it. It is a fefature documented?

@Ph0enixKM
Copy link
Member

@Mte90 yes, it is. Here in the documentation: https://docs.amber-lang.com/basic_syntax/functions#variable-references-ref

@Mte90 Mte90 requested review from hdwalters and b1ek November 5, 2024 11:09
@Mte90
Copy link
Member Author

Mte90 commented Nov 5, 2024

Implemented ref that I didn't knew about it.

Copy link
Member

@Ph0enixKM Ph0enixKM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to that you should create a new test that is it's own separate file for checking non-ref shorthand operators:

let sum = 42
sum += 32
echo sum

let sub = 64
sub -= 48
echo sub

// ...

src/tests/validity/variable_ref_operators.ab Outdated Show resolved Hide resolved
@Mte90
Copy link
Member Author

Mte90 commented Nov 5, 2024

We already have tests for shortand operators like in your example: https://github.com/amber-lang/amber/blob/master/src/tests/validity/shorthand_sub.ab

@Mte90 Mte90 requested a review from Ph0enixKM November 5, 2024 11:25
@Ph0enixKM
Copy link
Member

Yeah... it seems that we already have tests for shorthand operators and ref shorthand operators.

@b1ek b1ek merged commit d87e0c0 into amber-lang:master Nov 6, 2024
1 check passed
@Mte90 Mte90 deleted the 433 branch December 23, 2024 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants