@@ -1819,19 +1819,26 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
1819
1819
}
1820
1820
if (ASR::is_a<ASR::Variable_t>(*t)) {
1821
1821
ASR::Variable_t *var = ASR::down_cast<ASR::Variable_t>(t);
1822
- LFORTRAN_ASSERT (var->m_value );
1823
- if (ASR::is_a<ASR::ConstantComplex_t> (*var->m_value )) {
1822
+ // LFORTRAN_ASSERT(var->m_value);
1823
+ if (ASRUtils::is_complex (*var->m_type )) {
1824
1824
std::string attr = x.m_attr ;
1825
1825
if (attr == " imag" ) {
1826
- double val = ASR::down_cast<ASR::ConstantComplex_t>(var->m_value )->m_im ;
1827
- ASR::ttype_t *type = ASRUtils::TYPE (ASR::make_Real_t (al, x.base .base .loc ,
1828
- 8 , nullptr , 0 ));
1829
- tmp = ASR::make_ConstantReal_t (al, x.base .base .loc , val, type);
1826
+ ASR::expr_t *val = ASR::down_cast<ASR::expr_t >(ASR::make_Var_t (al, x.base .base .loc , t));
1827
+ ASR::symbol_t *fn_imag = resolve_intrinsic_function (x.base .base .loc , " imag" );
1828
+ Vec<ASR::expr_t *> args;
1829
+ args.reserve (al, 1 );
1830
+ args.push_back (al, val);
1831
+ make_call_helper (al, fn_imag, current_scope, args, " imag" , x.base .base .loc );
1832
+ return ;
1830
1833
} else if (attr == " real" ) {
1831
- double val = ASR::down_cast<ASR::ConstantComplex_t>(var->m_value )->m_re ;
1832
- ASR::ttype_t *type = ASRUtils::TYPE (ASR::make_Real_t (al, x.base .base .loc ,
1833
- 8 , nullptr , 0 ));
1834
- tmp = ASR::make_ConstantReal_t (al, x.base .base .loc , val, type);
1834
+ ASR::expr_t *val = ASR::down_cast<ASR::expr_t >(ASR::make_Var_t (al, x.base .base .loc , t));
1835
+ int kind = ASRUtils::extract_kind_from_ttype_t (var->m_type );
1836
+ ASR::ttype_t *dest_type = ASR::down_cast<ASR::ttype_t >(ASR::make_Real_t (al, x.base .base .loc ,
1837
+ kind, nullptr , 0 ));
1838
+ tmp = (ASR::asr_t *)ASR::down_cast<ASR::expr_t >(ASR::make_ImplicitCast_t (
1839
+ al, val->base .loc , val, ASR::cast_kindType::ComplexToReal, dest_type,
1840
+ nullptr ));
1841
+ return ;
1835
1842
} else {
1836
1843
throw SemanticError (" '" + attr + " ' is not implemented for Complex type" ,
1837
1844
x.base .base .loc );
0 commit comments