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

Review usage of if-then-else stack on nested ifs #80

Closed
javihern98 opened this issue Feb 21, 2025 · 2 comments · Fixed by #81
Closed

Review usage of if-then-else stack on nested ifs #80

javihern98 opened this issue Feb 21, 2025 · 2 comments · Fixed by #81
Assignees
Labels
bug Something isn't working

Comments

@javihern98
Copy link
Contributor

Overview

When adding a new AST object to handle Parenthesis expression, we found a bug related with the if-then-else stack.

The VTL code to test can be found in test.Bugs.GL_195_1:

B03.ANAMART_INSTRMNT_SHR_ONA_CRDTR := B03.INSTRMNT_FCT_TRNSFRRD_AMNT
    [ calc SHR_ONA_CRDTR := if OTSTNDNG_NMNL_AMNT = 0
            then 1 / NMBR_CRDTR
            else (
                if OBSRVD_AGNT_CD = CRDTR_ID
                then ( OTSTNDNG_NMNL_AMNT - TRNSFRRD_AMNT ) / OTSTNDNG_NMNL_AMNT
                else (
                    if OTSTNDNG_NMNL_AMNT * NMBR_CRDTRS_NT_OA = 0.0 then 1
                    else TRNSFRRD_AMNT / ( OTSTNDNG_NMNL_AMNT * NMBR_CRDTRS_NT_OA )
                )
            )
        ]
    [ keep SHR_ONA_CRDTR ] ;

We need to focus on OTSTNDNG_NMNL_AMNT. Once we have separated the then and else values, we need now to use only these separated values in the stack in the upcoming operations. The current error is related to index 17 as OTSTNDNG_NMNL_AMNT is 0. This index should not appear on the nested if as it will raise a DivisionByZero error.

Task to perform

  • Review the current implementation of if-then-else stack
  • Generate a new test that is similar to this (nested if uses different components than principal if) but with smaller names on the components (adhere to Id_1, Me_1 convention).
@mla2001 mla2001 added the bug Something isn't working label Feb 21, 2025
@javihern98
Copy link
Contributor Author

javihern98 commented Feb 21, 2025

AST code to add Parenthesis Expression

ASTConstructors/Expr.py (edit current function)

    def visitParenthesisExpr(self, ctx: Parser.ParenthesisExprContext):
        operand = self.visitExpr(list(ctx.getChildren())[1])
        return ParFunction(operand)

ASTConstructors/ExprComponent.py (edit current function)

    def visitParenthesisExprComp(self, ctx: Parser.ParenthesisExprContext):
        operand = self.visitExprComponent(list(ctx.getChildren())[1])
        return ParFunction(operand)

AST/__init__.py

@dataclass
class ParFunction(AST):
    """
    ParFunction: (operand)
    """

    operand: AST

Interpreter/__init__.py

    def visit_ParFunction(self, node: AST.ParFunction) -> Any:
        return self.visit(node.operand)

@javihern98
Copy link
Contributor Author

Same bug found on Anamart.BSeries.test_3

ANAMART_INSTRMNT_SHR_ONA_CRDTR := INSTRMNT_FCT_TRNSFRRD_AMNT[calc SHR_ONA_CRDTR :=
        if OTSTNDNG_NMNL_AMNT=0 
        then 1/NMBR_CRDTRS 
        else
            (
            if OBSRVD_AGNT_ID=CRDTR_ID 
            then (OTSTNDNG_NMNL_AMNT-TRNSFRRD_AMNT)/OTSTNDNG_NMNL_AMNT 
            else
                (if OTSTNDNG_NMNL_AMNT*NMBR_CRDTRS_NT_OA = 0.0 
                then 1 
                else
                    TRNSFRRD_AMNT/(OTSTNDNG_NMNL_AMNT*NMBR_CRDTRS_NT_OA)))
             ]
        [keep SHR_ONA_CRDTR];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants