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

planner: IR only contains function with mocks if functions are mocked #4746

Closed
srenatus opened this issue Jun 7, 2022 · 0 comments
Closed
Labels

Comments

@srenatus
Copy link
Contributor

srenatus commented Jun 7, 2022

package test

f = 1

p {
	q with time.now_ns as f
}

q {
	time.now_ns() == 1
}

run with opa build -t plan -e test, we find a plan that contains only one function for q:

            {
                "name": "g0.data.test.q",
                "params": [
                    0,
                    1
                ],
                "return": 2,
                "blocks": [
                    {
                        "stmts": [
                            {
                                "type": "ResetLocalStmt",
                                "stmt": {
                                    "target": 3,
                                    "file": 0,
                                    "col": 1,
                                    "row": 9
                                }
                            },
                            {
                                "type": "CallStmt",
                                "stmt": {
                                    "func": "g0.data.test.f",
                                    "args": [
                                        {
                                            "type": "local",
                                            "value": 0
                                        },
                                        {
                                            "type": "local",
                                            "value": 1
                                        }
                                    ],
                                    "result": 4,
                                    "file": 0,
                                    "col": 3,
                                    "row": 10
                                }
                            },
                            {
                                "type": "AssignVarStmt",
                                "stmt": {
                                    "source": {
                                        "type": "local",
                                        "value": 4
                                    },
                                    "target": 5,
                                    "file": 0,
                                    "col": 3,
                                    "row": 10
                                }
                            },
                            {
                                "type": "MakeNumberRefStmt",
                                "stmt": {
                                    "Index": 2,
                                    "target": 6,
                                    "file": 0,
                                    "col": 3,
                                    "row": 10
                                }
                            },
                            {
                                "type": "EqualStmt",
                                "stmt": {
                                    "a": {
                                        "type": "local",
                                        "value": 5
                                    },
                                    "b": {
                                        "type": "local",
                                        "value": 6
                                    },
                                    "file": 0,
                                    "col": 3,
                                    "row": 10
                                }
                            },
                            {
                                "type": "AssignVarOnceStmt",
                                "stmt": {
                                    "source": {
                                        "type": "bool",
                                        "value": true
                                    },
                                    "target": 3,
                                    "file": 0,
                                    "col": 1,
                                    "row": 9
                                }
                            }
                        ]
                    },
                    {
                        "stmts": [
                            {
                                "type": "IsDefinedStmt",
                                "stmt": {
                                    "source": 3,
                                    "file": 0,
                                    "col": 1,
                                    "row": 9
                                }
                            },
                            {
                                "type": "AssignVarOnceStmt",
                                "stmt": {
                                    "source": {
                                        "type": "local",
                                        "value": 3
                                    },
                                    "target": 2,
                                    "file": 0,
                                    "col": 1,
                                    "row": 9
                                }
                            }
                        ]
                    },
                    {
                        "stmts": [
                            {
                                "type": "ReturnLocalStmt",
                                "stmt": {
                                    "source": 2,
                                    "file": 0,
                                    "col": 1,
                                    "row": 9
                                }
                            }
                        ]
                    }
                ],
                "path": [
                    "g0",
                    "test",
                    "q"
                ]
            },

where we should expect two: one with a call to f, one with the original call to time.now_ns.

@srenatus srenatus added the bug label Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant