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

Slice of structs with slice members fails to be set coherently #3637

Closed
Tracked by #3363
grasshopper47 opened this issue Nov 29, 2023 · 1 comment
Closed
Tracked by #3363
Labels
bug Something isn't working

Comments

@grasshopper47
Copy link
Contributor

grasshopper47 commented Nov 29, 2023

Aim

@vezenovm continuation of #3476

global BEGIN_OBJECT    : u8 = 0x7B; // { left curly bracket
global END_OBJECT      : u8 = 0x7D; // } right curly bracket
global BACKSLASH       : u8 = 0x5C; // \ reverse solidus

global chars =
[
    "\0","\0","\0","\0","\0","\0","\0","\0","\0","\t","\n","\0","\0","\r","\0","\0","\0","\0","\0","\0","\0","\0","\0","\0","\0","\0","\0","\0","\0","\0","\0","\0",
    " ","!","\"","#","$","%","&","'","(",")","*","+",",","-",".","/",
    "0","1","2","3","4","5","6","7","8","9",
    ":",";","<","=",">","?","@",
    "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z",
    "[","\\","]","^","_","`",
    "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
    "{","|","}","~"
];

struct Property
{
    key : [u8]
,   value : [u8]
}

type Object = [Property];

struct JSON
{
    doc : Object
}

impl Property
{
    unconstrained
    fn print(self)
    {
        dep::std::println("{\nkey");
        for byte in self.key { let c = chars[byte]; dep::std::println(f"    {c}"); }
        dep::std::println("}");

        dep::std::println("value\n{");

        let mut object = false;
        for byte in self.value
        {
            if (object & (byte != END_OBJECT) & (byte != BACKSLASH))
            {
                dep::std::println(f"        {byte}");
            }
            else
            {
                let c = chars[byte];
                dep::std::println(f"    {c}");

                object = (byte == BEGIN_OBJECT);
            }
        }

        dep::std::println("}");
    }
}

impl JSON
{
    unconstrained
    fn store(mut self, prop : Property) -> Object
    {
        for i in 0..self.doc.len() { self.doc[i].value = prop.value; }

        self.doc
    }
}

#[test]
unconstrained
fn property_key_number_and_key_array_object()
{
    let mut json = JSON { doc: [ Property { key: "a".as_bytes(), value: "1".as_bytes() } ] };
    let mut prop = Property { key: "a".as_bytes(), value:"123".as_bytes() }; // remove the `mut` keyword here, and the output will be different

    json.doc = json.store(prop);

    for prop in json.doc { prop.print(); }
}

Expected Behavior

the expected output is:

key
{
    a
}
value
{
    1
    2
    3
}

Bug

actual output

key
{
    1
    
    
    a
    1
    2
    3
    
    
    
    
    
    
    
    
}
value
{
    
}

To Reproduce

Run the provided code

Installation Method

None

Nargo Version

nargo 0.19.4

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@grasshopper47 grasshopper47 added the bug Something isn't working label Nov 29, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Nov 29, 2023
@grasshopper47 grasshopper47 changed the title Slice of structs with slice members not set correctly Slice of structs with slice members fails to be set correctly Nov 29, 2023
@grasshopper47 grasshopper47 changed the title Slice of structs with slice members fails to be set correctly Slice of structs with slice members fails to be set coherently Nov 29, 2023
@vezenovm
Copy link
Contributor

vezenovm commented Feb 2, 2024

Nested slices have been banned and we are leaning into BoundedVec for now #4197 due to a combination of their complexity + inefficiency in ACIR.

Slice of slices may be brought back in the future, but we want to have parity in feature across our constrained and unconstrained environment. Apologies for any inconvenience this may cause. Closing this issue for now.

@vezenovm vezenovm closed this as completed Feb 2, 2024
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Feb 2, 2024
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
Archived in project
Development

No branches or pull requests

2 participants