lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.51k stars 164 forks source link

String repeat does not work with runtime values #2120

Open kabra1110 opened 1 year ago

kabra1110 commented 1 year ago
from lpython import i32

def test_str_repeat():
    i: i32 = 10
    s: str = 'a'
    print(s * i)

test_str_repeat()

This gives a compiler error, occurring here

                right_int = ASR::down_cast<ASR::IntegerConstant_t>(
                                                   ASRUtils::expr_value(right))->m_n;

An assertion to check non-nullptr in down_cast fails.

certik commented 1 year ago

It's assuming that "i" is a compile time constant, but it's a variable in this case.

kabra1110 commented 1 year ago

I did try changing the code to use Integer_t instead, but the issue appears to be it being a nullptr.