← index #11638Issue #7808
Related · high · value 4.063
QUERY · ISSUE

Type Inference issue when using struct in viper

openby GuillaumeLeclercopened 2023-05-28updated 2023-05-28
bug
MY_TYPE = {
    "var": 0 | uctypes.UINT32
}
storage = bytearray(uctypes.sizeof(MY_TYPE))

@micropython.viper
def bugreport():
    data = uctypes.struct(ptr32(storage), MY_TYPE)
    data.var += int(1)

bugreport()

For some reason data.var is an object even though it's type is clearly defined from the struct. the following error occurs:

ViperTypeError: can\'t do binary op between \'object\' and \'int\'
CANDIDATE · ISSUE

Minor Viper Flaw: Misleading error message

openby RaulKompassopened 2021-09-16updated 2021-09-20

Accessing an undefined variable in Python and Micropython:

def quot(a:int, b:int) -> int:
    return c//b

results in NameError: name 'c' isn't defined during execution.

Above function with @micropython.viper results in ViperTypeError: return expected 'int' but got 'object'during compilation.
Just now I realize that viper has to assume that c is some global python object. Which means the error message is correct. But it is misleading.
An addition like name 'c' isn't defined while compiling would be helpful imho.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied