this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

tools/fix: add tests for value alias conversion when "self" is in scope

Test cases where "cue fix --exp=aliasv2" converts old-style value
aliases (X={...}) to "let X = self" in structs where "self" is already
defined as a field, let clause, or alias. The generated "let X = self"
binds to the wrong value in these cases.

For #4151.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Iaeabbd3fd53f94a3aab95843ee7e2196c14aa935
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1231143
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>

+123
+123
tools/fix/testdata/aliasv2.txtar
··· 131 131 base: 20 132 132 } 133 133 } 134 + -- h.cue -- 135 + package foo 136 + 137 + // Test value alias conversion when "self" is already in scope, 138 + // such as via a field, let clause, or alias named "self". 139 + // The generated "let X = self" may bind to the wrong "self" 140 + // unless "__self" is used to refer to the builtin. 141 + 142 + // Field named self in same struct 143 + samestruct: X={ 144 + i: X.self 145 + self: 42 146 + } 147 + 148 + // Field named self in enclosing struct 149 + enclosingfield: { 150 + self: 42 151 + inner: X={ 152 + i: X.a 153 + a: 1 154 + } 155 + } 156 + 157 + // Let self in enclosing struct 158 + enclosinglet: { 159 + let self = {z: 99} 160 + inner: X={ 161 + i: X.a 162 + a: 1 163 + j: self.z 164 + } 165 + } 166 + 167 + // Field alias named self at same scope 168 + aliassamescope: { 169 + self=bar: { 170 + data: 1 171 + } 172 + baz: self.data 173 + foo: X={ 174 + i: X.a 175 + a: 1 176 + } 177 + } 178 + 179 + // Field alias named self in enclosing struct 180 + aliasenclosing: { 181 + self=bar: { 182 + data: 1 183 + } 184 + baz: self.data 185 + inner: { 186 + foo: X={ 187 + i: X.a 188 + a: 1 189 + } 190 + } 191 + } 134 192 -- out/fixmod -- 135 193 --- cue.mod/module.cue 136 194 module: "test.example" ··· 278 336 base: 20 279 337 } 280 338 } 339 + --- h.cue 340 + @experiment(aliasv2) 341 + 342 + package foo 343 + 344 + // Test value alias conversion when "self" is already in scope, 345 + // such as via a field, let clause, or alias named "self". 346 + // The generated "let X = self" may bind to the wrong "self" 347 + // unless "__self" is used to refer to the builtin. 348 + 349 + // Field named self in same struct 350 + samestruct: { 351 + let X = self 352 + i: X.self 353 + self: 42 354 + } 355 + 356 + // Field named self in enclosing struct 357 + enclosingfield: { 358 + self: 42 359 + inner: { 360 + let X = self 361 + i: X.a 362 + a: 1 363 + } 364 + } 365 + 366 + // Let self in enclosing struct 367 + enclosinglet: { 368 + let self = {z: 99} 369 + inner: { 370 + let X = self 371 + i: X.a 372 + a: 1 373 + j: self.z 374 + } 375 + } 376 + 377 + // Field alias named self at same scope 378 + aliassamescope: { 379 + bar~self: { 380 + data: 1 381 + } 382 + baz: self.data 383 + foo: { 384 + let X = self 385 + i: X.a 386 + a: 1 387 + } 388 + } 389 + 390 + // Field alias named self in enclosing struct 391 + aliasenclosing: { 392 + bar~self: { 393 + data: 1 394 + } 395 + baz: self.data 396 + inner: { 397 + foo: { 398 + let X = self 399 + i: X.a 400 + a: 1 401 + } 402 + } 403 + }