Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Constant variables are usable now #630

Merged
merged 10 commits into from
Dec 16, 2024
Merged

Conversation

Ph0enixKM
Copy link
Member

@Ph0enixKM Ph0enixKM commented Dec 5, 2024

  • Translating constants changed from using Bash's declare -r to a regular variable due to the problem of no ability to redeclare them in inner scopes like loops and functions
  • Moved tests from errors.rs to erroring/ directory to align the testing logic with tests for validity and standard library

@Ph0enixKM Ph0enixKM linked an issue Dec 5, 2024 that may be closed by this pull request
@Mte90 Mte90 requested review from hdwalters, b1ek and KrosFire December 5, 2024 11:29
@Ph0enixKM Ph0enixKM added bug Something isn't working compiler urgent Requires immediate actions labels Dec 5, 2024
@mks-h

This comment was marked as resolved.

@Mte90 Mte90 requested a review from mks-h December 6, 2024 09:44
@hdwalters

This comment was marked as resolved.

src/modules/statement/stmt.rs Outdated Show resolved Hide resolved
src/modules/variable/init.rs Outdated Show resolved Hide resolved
src/tests/validity/variable_constant_condition.ab Outdated Show resolved Hide resolved
src/tests/validity/variable_constant_condition.ab Outdated Show resolved Hide resolved
@Ph0enixKM Ph0enixKM self-assigned this Dec 10, 2024
@Ph0enixKM
Copy link
Member Author

Problem

There is a huge problem with Bash variables. They behave similarly to var variables in JavaScript. This means that variables are being created in the scope of function.

Example:

local test=12
if [[ $test == "12" ]]; then
    local test=24
    echo $test # Outputs: 24
fi

echo $test # Outputs: 24

Solution

This can be resolved in two ways:

  1. Creating subshells - adds a substantial overhead
  2. Name mangling - requires name mangling

I think that the second solution is far better. In it's case - I will check whether the variable has been declared in a scope before and add gen_id() number to it's name. Do you agree with this approach?

@Ph0enixKM Ph0enixKM requested a review from hdwalters December 11, 2024 17:27
Copy link
Contributor

@hdwalters hdwalters left a comment

Choose a reason for hiding this comment

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

Some minor suggestions, but otherwise good to go.

src/tests/erroring/variable_constant_shorthand_add.ab Outdated Show resolved Hide resolved
src/tests/erroring/variable_constant.ab Outdated Show resolved Hide resolved
src/utils/metadata/parser.rs Outdated Show resolved Hide resolved
src/tests/mod.rs Show resolved Hide resolved
@mks-h
Copy link
Member

mks-h commented Dec 12, 2024

First of all, I dislike the idea of adding /src/tests/erroring functionality in this PR, as it is out of scope. Can you separate it, pretty please?

@Ph0enixKM
Copy link
Member Author

First of all, I dislike the idea of adding /src/tests/erroring functionality in this PR, as it is out of scope. Can you separate it, pretty please?

You want me to remove the tests and add them separately in the new form in a new PR? I know that it's pretty messy but it adds extra work and brings little value.

@mks-h
Copy link
Member

mks-h commented Dec 12, 2024

Fair enough, but in the future please don't combine separate issues into a single PR.

Copy link
Member

@b1ek b1ek left a comment

Choose a reason for hiding this comment

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

what did you exactly change to achieve the "usefulness"? the description is empty. i will not try to guess it by the diffs. please explain in the description what you have changed and why, and what is overall the thought process here

also, why are there new tests for arrays and failable functions? they seem totally irrelevant to this PR

@Ph0enixKM
Copy link
Member Author

@b1ek I moved the files from errors.rs to the erroring/ directory designed for tests. And the full description is in the issue that this PR is linked to

@Ph0enixKM
Copy link
Member Author

I'll write a description of what this PR does precisely

@Ph0enixKM Ph0enixKM requested a review from b1ek December 13, 2024 10:50
src/modules/variable/init.rs Show resolved Hide resolved
src/modules/variable/mod.rs Show resolved Hide resolved
Copy link
Member

@b1ek b1ek left a comment

Choose a reason for hiding this comment

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

lets merge

@b1ek b1ek merged commit 19c3e35 into master Dec 16, 2024
1 check passed
@Ph0enixKM Ph0enixKM deleted the 627-bug-constants-in-a-loop-fail branch December 19, 2024 11:07
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working compiler urgent Requires immediate actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Constants in a loop fail
4 participants