@@ -2080,9 +2080,10 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
20802080 tmp = ASR::make_ConstantLogical_t (al, x.base .base .loc , result, type);
20812081 return ;
20822082 } else if (call_name == " int" ) {
2083+ ASR::ttype_t *type = ASRUtils::TYPE (ASR::make_Integer_t (al,
2084+ x.base .base .loc , 4 , nullptr , 0 ));
20832085 if (args.size () == 0 ) {
2084- tmp = ASR::make_ConstantInteger_t (al, x.base .base .loc , 0 ,
2085- ASRUtils::TYPE (ASR::make_Integer_t (al, x.base .base .loc , 4 , nullptr , 0 )));
2086+ tmp = ASR::make_ConstantInteger_t (al, x.base .base .loc , 0 , type);
20862087 return ;
20872088 }
20882089 ASR::expr_t * int_expr = args[0 ];
@@ -2093,31 +2094,32 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
20932094 }
20942095 if (ASRUtils::is_integer (*int_type)) {
20952096 int64_t ival = ASR::down_cast<ASR::ConstantInteger_t>(ASRUtils::expr_value (int_expr))->m_n ;
2096- tmp = ASR::make_ConstantInteger_t (al, x.base .base .loc , ival, int_type );
2097+ tmp = ASR::make_ConstantInteger_t (al, x.base .base .loc , ival, type );
20972098
20982099 } else if (ASRUtils::is_character (*int_type)) {
20992100 // convert a string to an int
21002101 char * c = ASR::down_cast<ASR::ConstantString_t>(ASRUtils::expr_value (int_expr))->m_s ;
21012102 std::string s = std::string (c);
21022103 int64_t ival = std::stoll (s);
2103- tmp = ASR::make_ConstantInteger_t (al, x.base .base .loc , ival, int_type );
2104+ tmp = ASR::make_ConstantInteger_t (al, x.base .base .loc , ival, type );
21042105
21052106 } else if (ASRUtils::is_real (*int_type)) {
21062107 int64_t ival = ASR::down_cast<ASR::ConstantReal_t>(ASRUtils::expr_value (int_expr))->m_r ;
2107- tmp = ASR::make_ConstantInteger_t (al, x.base .base .loc , ival, int_type );
2108+ tmp = ASR::make_ConstantInteger_t (al, x.base .base .loc , ival, type );
21082109 } else if (ASRUtils::is_logical (*int_type)) {
21092110 bool rv = ASR::down_cast<ASR::ConstantLogical_t>(int_expr)->m_value ;
21102111 int8_t val = rv ? 1 : 0 ;
2111- tmp = ASR::make_ConstantInteger_t (al, x.base .base .loc , val, int_type );
2112+ tmp = ASR::make_ConstantInteger_t (al, x.base .base .loc , val, type );
21122113 } else {
21132114 throw SemanticError (" int() argument must be real, integer, logical, or a string, not '" +
21142115 ASRUtils::type_to_str (int_type) + " '" , x.base .base .loc );
21152116 }
21162117 return ;
21172118 } else if (call_name == " float" ) {
2119+ ASR::ttype_t * type = ASRUtils::TYPE (ASR::make_Real_t (al,
2120+ x.base .base .loc , 8 , nullptr , 0 ));
21182121 if (args.size () == 0 ) {
2119- tmp = ASR::make_ConstantReal_t (al, x.base .base .loc , 0.0 ,
2120- ASRUtils::TYPE (ASR::make_Real_t (al, x.base .base .loc , 8 , nullptr , 0 )));
2122+ tmp = ASR::make_ConstantReal_t (al, x.base .base .loc , 0.0 , type);
21212123 return ;
21222124 }
21232125 ASR::expr_t * float_expr = args[0 ];
@@ -2128,21 +2130,21 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
21282130 }
21292131 if (ASRUtils::is_real (*float_type)) {
21302132 float rv = ASR::down_cast<ASR::ConstantReal_t>(ASRUtils::expr_value (float_expr))->m_r ;
2131- tmp = ASR::make_ConstantReal_t (al, x.base .base .loc , rv, float_type );
2133+ tmp = ASR::make_ConstantReal_t (al, x.base .base .loc , rv, type );
21322134 } else if (ASRUtils::is_integer (*float_type)) {
21332135 // convert an int to a float using implicit cast
21342136 double rv = ASR::down_cast<ASR::ConstantInteger_t>(ASRUtils::expr_value (float_expr))->m_n ;
2135- tmp = ASR::make_ConstantReal_t (al, x.base .base .loc , rv, float_type );
2137+ tmp = ASR::make_ConstantReal_t (al, x.base .base .loc , rv, type );
21362138 } else if (ASRUtils::is_logical (*float_type)) {
21372139 bool rv = ASR::down_cast<ASR::ConstantLogical_t>(float_expr)->m_value ;
21382140 float val = rv ? 1.0 : 0.0 ;
2139- tmp = ASR::make_ConstantReal_t (al, x.base .base .loc , val, float_type );
2141+ tmp = ASR::make_ConstantReal_t (al, x.base .base .loc , val, type );
21402142 } else if (ASRUtils::is_character (*float_type)) {
21412143 // convert a string to a float
21422144 char * c = ASR::down_cast<ASR::ConstantString_t>(ASRUtils::expr_value (float_expr))->m_s ;
21432145 std::string s = std::string (c);
21442146 float rv = std::stof (s);
2145- tmp = ASR::make_ConstantReal_t (al, x.base .base .loc , rv, float_type );
2147+ tmp = ASR::make_ConstantReal_t (al, x.base .base .loc , rv, type );
21462148 } else {
21472149 throw SemanticError (" float() argument must be real, integer, logical, or a string, not '" +
21482150 ASRUtils::type_to_str (float_type) + " '" , x.base .base .loc );
0 commit comments