jrsonnet icon indicating copy to clipboard operation
jrsonnet copied to clipboard

Destructuring bind default values can't be overriden

Open simonrouse9461 opened this issue 1 year ago • 2 comments

This works fine:

local {a = 1} = {};
a

Result:

1

But this doesn't:

local {a = 1} = {a: 3};
a

Error:

runtime error: too many fields, and rest not found
    <string>:3:9-11: variable <a> access

Is this intended? Or is it a bug?

simonrouse9461 avatar Jun 20 '24 03:06 simonrouse9461

I figured out that if I do this, it will work properly:

local {a = 1, ...} = {a: 3};
a

Result:

3

I don't thinks this is intuitive or documented anywhere.

simonrouse9461 avatar Jun 20 '24 03:06 simonrouse9461

Yep, looks like a bug. Destructuring system is not being tested much, I'll look into it.

CertainLach avatar Jun 20 '24 11:06 CertainLach

@CertainLach @simonrouse9461 But this will not get a valid result in jsonnet.

local {a = 1} = {};
a

gives me :

Error: example1.jsonnet:1:7-8 Expected token IDENTIFIER but got "{"

local {a = 1} = {};


He-Pin avatar Apr 28 '25 02:04 He-Pin