Commit 03646dd
authored
topdown: Fix PE not namespacing vars in comprehensions nested inside
Partial-eval doesn't properly namespace in-scope vars inside
comprehensions when they're nested inside an `every` statement.
E.g. PE on `data.test.p = true` for the policy:
```rego
package test
p if {
every x in input.x {
{y | y := input.y; y < x}
}
}
```
will emit:
```rego
every __local0__1, __local1__1 in input.x {
{__local2__ | __local2__ = input.y; lt(__local2__, __local1__)}
}
```
Notice how the comprehension makes a reference to `__local1__`, which
has been namespaced to `__local1__1` in the outer scope, making the
result query invalid.
This fix checks for comprehension terms inside the `every`-body and
amends them. Which gives us the updated result query:
```rego
every __local0__1, __local1__1 in input.x {
{__local2__1 | __local2__1 = input.y; lt(__local2__1, __local1__1)}
}
```
where vars inside the comprehension are now namespaced.
Note: this is a pretty narrow edge-case, so I wouldn't expect many real
cases in the wild.
---------
Signed-off-by: Johan Fylling <johan.dev@fylling.se>every (#8816)1 parent bf2bb52 commit 03646dd
2 files changed
Lines changed: 173 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4204 | 4204 | | |
4205 | 4205 | | |
4206 | 4206 | | |
4207 | | - | |
| 4207 | + | |
| 4208 | + | |
| 4209 | + | |
| 4210 | + | |
| 4211 | + | |
4208 | 4212 | | |
4209 | 4213 | | |
4210 | | - | |
| 4214 | + | |
4211 | 4215 | | |
4212 | 4216 | | |
4213 | | - | |
| 4217 | + | |
| 4218 | + | |
| 4219 | + | |
4214 | 4220 | | |
4215 | 4221 | | |
4216 | 4222 | | |
4217 | 4223 | | |
4218 | 4224 | | |
4219 | | - | |
| 4225 | + | |
4220 | 4226 | | |
4221 | 4227 | | |
4222 | | - | |
| 4228 | + | |
4223 | 4229 | | |
4224 | 4230 | | |
4225 | 4231 | | |
4226 | | - | |
| 4232 | + | |
| 4233 | + | |
| 4234 | + | |
| 4235 | + | |
| 4236 | + | |
4227 | 4237 | | |
4228 | 4238 | | |
4229 | | - | |
| 4239 | + | |
| 4240 | + | |
| 4241 | + | |
| 4242 | + | |
| 4243 | + | |
4230 | 4244 | | |
4231 | 4245 | | |
4232 | | - | |
| 4246 | + | |
| 4247 | + | |
| 4248 | + | |
| 4249 | + | |
| 4250 | + | |
4233 | 4251 | | |
4234 | | - | |
| 4252 | + | |
| 4253 | + | |
| 4254 | + | |
4235 | 4255 | | |
4236 | 4256 | | |
| 4257 | + | |
| 4258 | + | |
| 4259 | + | |
| 4260 | + | |
| 4261 | + | |
| 4262 | + | |
| 4263 | + | |
| 4264 | + | |
4237 | 4265 | | |
4238 | 4266 | | |
4239 | 4267 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3051 | 3051 | | |
3052 | 3052 | | |
3053 | 3053 | | |
| 3054 | + | |
| 3055 | + | |
| 3056 | + | |
| 3057 | + | |
| 3058 | + | |
| 3059 | + | |
| 3060 | + | |
| 3061 | + | |
| 3062 | + | |
| 3063 | + | |
| 3064 | + | |
| 3065 | + | |
| 3066 | + | |
| 3067 | + | |
| 3068 | + | |
| 3069 | + | |
| 3070 | + | |
| 3071 | + | |
| 3072 | + | |
| 3073 | + | |
| 3074 | + | |
| 3075 | + | |
| 3076 | + | |
| 3077 | + | |
| 3078 | + | |
| 3079 | + | |
| 3080 | + | |
| 3081 | + | |
| 3082 | + | |
| 3083 | + | |
| 3084 | + | |
| 3085 | + | |
| 3086 | + | |
| 3087 | + | |
| 3088 | + | |
| 3089 | + | |
| 3090 | + | |
| 3091 | + | |
| 3092 | + | |
| 3093 | + | |
| 3094 | + | |
| 3095 | + | |
| 3096 | + | |
| 3097 | + | |
| 3098 | + | |
| 3099 | + | |
| 3100 | + | |
| 3101 | + | |
| 3102 | + | |
| 3103 | + | |
| 3104 | + | |
| 3105 | + | |
| 3106 | + | |
| 3107 | + | |
| 3108 | + | |
| 3109 | + | |
| 3110 | + | |
| 3111 | + | |
| 3112 | + | |
| 3113 | + | |
| 3114 | + | |
| 3115 | + | |
| 3116 | + | |
| 3117 | + | |
| 3118 | + | |
| 3119 | + | |
| 3120 | + | |
| 3121 | + | |
| 3122 | + | |
| 3123 | + | |
| 3124 | + | |
| 3125 | + | |
| 3126 | + | |
| 3127 | + | |
| 3128 | + | |
| 3129 | + | |
| 3130 | + | |
| 3131 | + | |
| 3132 | + | |
| 3133 | + | |
| 3134 | + | |
| 3135 | + | |
| 3136 | + | |
| 3137 | + | |
| 3138 | + | |
| 3139 | + | |
| 3140 | + | |
| 3141 | + | |
| 3142 | + | |
| 3143 | + | |
| 3144 | + | |
| 3145 | + | |
| 3146 | + | |
| 3147 | + | |
| 3148 | + | |
| 3149 | + | |
| 3150 | + | |
| 3151 | + | |
| 3152 | + | |
| 3153 | + | |
| 3154 | + | |
| 3155 | + | |
| 3156 | + | |
| 3157 | + | |
| 3158 | + | |
| 3159 | + | |
| 3160 | + | |
| 3161 | + | |
| 3162 | + | |
| 3163 | + | |
| 3164 | + | |
| 3165 | + | |
| 3166 | + | |
| 3167 | + | |
| 3168 | + | |
| 3169 | + | |
| 3170 | + | |
| 3171 | + | |
| 3172 | + | |
| 3173 | + | |
| 3174 | + | |
| 3175 | + | |
| 3176 | + | |
| 3177 | + | |
| 3178 | + | |
| 3179 | + | |
| 3180 | + | |
| 3181 | + | |
| 3182 | + | |
| 3183 | + | |
| 3184 | + | |
| 3185 | + | |
| 3186 | + | |
| 3187 | + | |
| 3188 | + | |
| 3189 | + | |
3054 | 3190 | | |
3055 | 3191 | | |
3056 | 3192 | | |
| |||
0 commit comments