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

Declaring and assigning const array with const size #1047

Closed
sshravan opened this issue Nov 7, 2021 · 1 comment
Closed

Declaring and assigning const array with const size #1047

sshravan opened this issue Nov 7, 2021 · 1 comment
Assignees

Comments

@sshravan
Copy link

sshravan commented Nov 7, 2021

Description

Const value not realized during assignment.

Environment

  • Compiler version: 0.7.7 (fc55d88)
  • Operating system: Ubuntu

Steps to Reproduce

bug/utils/matrix.zok

const u32 SIZE = 4
const field[SIZE][SIZE] MATRIX = [
	[
	       1,       2,       3,       4
	],
	[
	       5,       6,       7,       8
	],
	[
	       8,       7,       6,       5
	],
	[
	       4,       3,       2,       1
	]
]

bug/main.zok

from "./utils/matrix" import MATRIX
const u32 SIZE = 4

def main(field scalar):
    field[SIZE][SIZE] result = [[0; SIZE]; SIZE]
    for u32 i in 0..SIZE do
        for u32 j in 0..SIZE do
            result[i][j] = MATRIX[i][j] * scalar
        endfor
    endfor

    assert(result == [[0; SIZE]; SIZE])
    return
$ zokrates compile -i bug/main.zok      
Compiling bug/main.zok

Compilation failed:

bug/main.zok:
	Expression of type `field[4][4]` cannot be assigned to constant `bug/main.zok/MATRIX` of type `field[bug/./utils/matrix.zok/SIZE][bug/./utils/matrix.zok/SIZE]`

However, replacing const field[SIZE][SIZE] MATRIX with const field[4][4] MATRIX in bug/utils/matrix.zok solves the issue though.

@sshravan sshravan changed the title Declaring and assigning const array with const array size Declaring and assigning const array with const size Nov 7, 2021
@dark64
Copy link
Member

dark64 commented Nov 11, 2021

Hey @sshravan, thanks for the report. This is definitely a bug.

devnote: I've reduced the issue to:

// utils/mod2.zok
// surprisingly, it works when moving this module one folder up (./mod2) 
const field A = 1
const field B = A + 1

// mod1.zok
from "./utils/mod2" import B

def main():
    return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants