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

Bugfix/nw23001440/omitted parameter on program call #405

Merged
merged 8 commits into from
Jan 26, 2024

Conversation

foresti-smeup
Copy link
Collaborator

Description

Manage program call with omitted entry parameters (for example, call a program with 3 entries passing only 2 values)
Rules:

  • No error if called program don't use omitted entry
  • Throw exception if called program try to use the omitted entry var

In the previous version, calling a program with omitted parameters always threw a missing parameter exception, even if the called program made no use of the undefined variable.

Related to:

  • MULANGT90-T10_A60-P04

Checklist:

  • There are tests regarding this feature
  • The code follows the Kotlin conventions (run ./gradlew ktlintCheck)
  • The code passes all tests (run ./gradlew check)
  • There is a specific documentation in the docs directory

…omitted_parameter_on_call

# Conflicts:
#	rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/evaluation/SmeupInterpreterTest.kt
…omitted_parameter_on_call

# Conflicts:
#	rpgJavaInterpreter-core/src/test/kotlin/com/smeup/rpgparser/evaluation/SmeupInterpreterTest.kt
Copy link
Collaborator

@lanarimarco lanarimarco left a comment

Choose a reason for hiding this comment

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

You are exploiting VoidValue, which was born to handle rpg functions that returns nothing to handle this issue, this choice forced you to introduce many changes. In addition you are adding in SymbolTable something that it should not be in SymbolTable.

Wasn't there a cleaner approach?

@foresti-smeup
Copy link
Collaborator Author

You are exploiting VoidValue, which was born to handle rpg functions that returns nothing to handle this issue, this choice forced you to introduce many changes. In addition you are adding in SymbolTable something that it should not be in SymbolTable.

At first I created a new NullValue class to manage variables without value assignment. Then I preferred to use the VoidValue class because it was already present and it seemed not used in any part of the code (its methods were mostly marked as TODO). If you prefer, I can restore the NullValue class and leave the VoidValue class unchanged.

For the SymbolTable issue, I also don't like the solution of throwing an exception when reading a value but I haven't found any alternative way to understand whether a variable is used or not in the called program.
Surely there is a cleaner solution but I haven't found it.

@lanarimarco
Copy link
Collaborator

You are exploiting VoidValue, which was born to handle rpg functions that returns nothing to handle this issue, this choice forced you to introduce many changes. In addition you are adding in SymbolTable something that it should not be in SymbolTable.

At first I created a new NullValue class to manage variables without value assignment. Then I preferred to use the VoidValue class because it was already present and it seemed not used in any part of the code (its methods were mostly marked as TODO). If you prefer, I can restore the NullValue class and leave the VoidValue class unchanged.

For the SymbolTable issue, I also don't like the solution of throwing an exception when reading a value but I haven't found any alternative way to understand whether a variable is used or not in the called program. Surely there is a cleaner solution but I haven't found it.

I'll think about it and let you know by tomorrow.

Copy link
Collaborator

@lanarimarco lanarimarco left a comment

Choose a reason for hiding this comment

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

Now your implementation is clearer, because I realized that the only way to manage this behavior is at runtime.
But maybe you are using VoidValue not properly.
You have implemented some methods in a logically wrong way, as mentioned in my comments.
Try to follow my suggestions, if you are not able to do it, it could be necessary define a new value, for instance NullValue.

@lanarimarco
Copy link
Collaborator

lanarimarco commented Jan 25, 2024 via email

Copy link
Collaborator

@lanarimarco lanarimarco left a comment

Choose a reason for hiding this comment

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

I don't understand why the NullValue check is not in SymbolTable.get(DataDefinition).
Since that NullValue is something like a red semaphore that denies the variable access, you should implement this in SymbolTable.get(DataDefinition).

@lanarimarco
Copy link
Collaborator

I have tried to reimplement as I thought was better (SymbolTable.get) but it would have been a disaster, than, I have to admit that your idea is as best as we can do.

Copy link
Collaborator

@lanarimarco lanarimarco left a comment

Choose a reason for hiding this comment

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

Ok

@lanarimarco lanarimarco merged commit 310a12c into develop Jan 26, 2024
3 checks passed
@foresti-smeup
Copy link
Collaborator Author

I also try this solution with modified SymbolTable.get:

override operator fun get(data: AbstractDataDefinition): Value {
        val value =  when (data.scope) {
            Scope.Program -> (programSymbolTable as SymbolTable).getLocal(data)
            Scope.Local -> getLocal(data)
            Scope.Static -> TODO()
        }
        if (value is NullValue) {
            throw IllegalArgumentException("Void value for ${data.name}")
        }
        return value
    }

but also in my test the result was a half disaster.

@lanarimarco
Copy link
Collaborator

lanarimarco commented Jan 26, 2024 via email

@lanarimarco lanarimarco deleted the bugfix/NW23001440/omitted_parameter_on_call branch January 31, 2024 09:13
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.

2 participants