@@ -1847,19 +1847,26 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
1847
1847
}
1848
1848
if (ASR::is_a<ASR::Variable_t>(*t)) {
1849
1849
ASR::Variable_t *var = ASR::down_cast<ASR::Variable_t>(t);
1850
- LFORTRAN_ASSERT (var->m_value );
1851
- if (ASR::is_a<ASR::ConstantComplex_t> (*var->m_value )) {
1850
+ // LFORTRAN_ASSERT(var->m_value);
1851
+ if (ASRUtils::is_complex (*var->m_type )) {
1852
1852
std::string attr = x.m_attr ;
1853
1853
if (attr == " imag" ) {
1854
- double val = ASR::down_cast<ASR::ConstantComplex_t>(var->m_value )->m_im ;
1855
- ASR::ttype_t *type = ASRUtils::TYPE (ASR::make_Real_t (al, x.base .base .loc ,
1856
- 8 , nullptr , 0 ));
1857
- tmp = ASR::make_ConstantReal_t (al, x.base .base .loc , val, type);
1854
+ ASR::expr_t *val = ASR::down_cast<ASR::expr_t >(ASR::make_Var_t (al, x.base .base .loc , t));
1855
+ ASR::symbol_t *fn_imag = resolve_intrinsic_function (x.base .base .loc , " imag" );
1856
+ Vec<ASR::expr_t *> args;
1857
+ args.reserve (al, 1 );
1858
+ args.push_back (al, val);
1859
+ make_call_helper (al, fn_imag, current_scope, args, " imag" , x.base .base .loc );
1860
+ return ;
1858
1861
} else if (attr == " real" ) {
1859
- double val = ASR::down_cast<ASR::ConstantComplex_t>(var->m_value )->m_re ;
1860
- ASR::ttype_t *type = ASRUtils::TYPE (ASR::make_Real_t (al, x.base .base .loc ,
1861
- 8 , nullptr , 0 ));
1862
- tmp = ASR::make_ConstantReal_t (al, x.base .base .loc , val, type);
1862
+ ASR::expr_t *val = ASR::down_cast<ASR::expr_t >(ASR::make_Var_t (al, x.base .base .loc , t));
1863
+ int kind = ASRUtils::extract_kind_from_ttype_t (var->m_type );
1864
+ ASR::ttype_t *dest_type = ASR::down_cast<ASR::ttype_t >(ASR::make_Real_t (al, x.base .base .loc ,
1865
+ kind, nullptr , 0 ));
1866
+ tmp = (ASR::asr_t *)ASR::down_cast<ASR::expr_t >(ASR::make_ImplicitCast_t (
1867
+ al, val->base .loc , val, ASR::cast_kindType::ComplexToReal, dest_type,
1868
+ nullptr ));
1869
+ return ;
1863
1870
} else {
1864
1871
throw SemanticError (" '" + attr + " ' is not implemented for Complex type" ,
1865
1872
x.base .base .loc );
0 commit comments