← index #9114Issue #1847
Related · high · value 0.090
QUERY · ISSUE

Viper bug: integers > 0x3fffffff appear as python objects

openby rkompassopened 2022-08-26updated 2023-04-16
bug

The bug presumably is a result of the same logic as the now closed #8956 (perhaps the fix is also as simple).

Integers outside the mpy small int range ( > 0x3fffffff) are handled as python objects in viper.
This rather should happen with integers > 0xffffffff.

Code to illustrate the issue:

# @micropython.viper
# def largeint(a) -> int:
#     b = a & 0xfffffffe
#     return b                   #  ->  ViperTypeError: return expected 'int' but got 'object'

# print(largeint(3))

@micropython.viper
def largeint2(a):
    b = a & 0xfffffffe           #      works, but b is now a python object rather than a viper integer
    return b

print(largeint2(3))


gv = b'\x03\x00\x00\x00'

@micropython.viper
def and32(p:ptr32):
    p[0] = p[0] & 0xfffffffe              # -> ViperTypeError: can't do binary op between 'int' and 'object'
                                          # but  works with 0x3ffffffe and with int(0xfffffffe)

print('Before: ', int.from_bytes(gv, 'little'))   #  -> 3
and32(gv) 
print('After: ', int.from_bytes(gv, 'little'))    # should be 2, but does not work
CANDIDATE · ISSUE

viper: ViperTypeError: can't do binary op between 'uint' and 'uint'

closedby peterhinchopened 2016-02-15updated 2020-06-26

The following produces the above error at compile time (only with uints - compiles and runs with int)

@micropython.viper
def foo(arg1: uint, arg2: uint) -> uint:
    return arg1 + arg2

MicroPython v1.6-35-ge372e83 on 2016-02-11; PYBv1.0 with STM32F405RG

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