Skip to content

Conversation

@czgdp1807
Copy link
Collaborator

Closes #1626


if( init_expr && current_body) {
if( init_expr && current_body &&
(is_runtime_expression || !is_variable_const)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Only those variables will be initialised by converting to assignments which are non-constant or have a runtime expressions. Also an error is thrown if a constant variable is not initialised at declaration (see lines 2215 to 2219).

@czgdp1807 czgdp1807 marked this pull request as ready for review March 26, 2023 14:44
+ std::string(x.m_name) + ")");

if( symtab->parent == nullptr ) {
// For nowRestrict this check only to variables which are present
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// For nowRestrict this check only to variables which are present
// For now restrict this check only to variables which are present

Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

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

I think that this is good, thanks for fixing it and adding a test!

I suggest we merge it, and if there are more issues, we'll tackle it as we discover it.

@czgdp1807
Copy link
Collaborator Author

Okay. Let me check if verify changes work with LFortran. Then I will merge both the PRs.

1. Only those variables which are constant and have a compile time initialisation expression will have non-nullptr values for m_symbolic_value and m_value
2. Rest all will be converted to assignment statements.
@czgdp1807 czgdp1807 merged commit 6ebd4b8 into lcompilers:main Mar 27, 2023
@czgdp1807 czgdp1807 deleted the var_init branch March 27, 2023 14:39
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.

C backend: variable is initialized twice

2 participants