Open rebcabin opened 7 months ago
I narrowed this down to dtype=numpy.int16
causes the exception, but dtype=int16
with from numpy import int16
avoids the error.
Here is a full program that avoids the error:
from numpy import empty, int16
from lpython import (i16, i32)
def main():
ai16: i16[15, 3] = empty((15, 3), dtype=int16)
# A_nm: i16[15, 3] = empty((15, 3), dtype=numpy.int16)
print ("hello, world!")
if __name__ == "__main__":
main()
@rebcabin If we compare the ast in both cases WIth error :
[(dtype
(Attribute
(Name
numpy
Load
)
int16
Load
))]
Without error:
[(dtype
(Name
int16
Load
))]
The error is thrown by line 7589 in python_ast_to_asr.cpp as the below function call returns false.
AST::is_a<AST::Name_t>(*x.m_keywords[0].m_value)
is_a function is defined as:
template <class T, class U>
inline bool is_a(const U &x)
{
return T::class_type == x.type;
}
I think there is a need of another definition of is_a where such node (Name + attribute) is checked for equality.
Another code containing a similar (Name + attribute) node doesn't throw this exception
import math
print(math.sqrt(9.0))
passes CPython but not lpython