@@ -1028,13 +1028,38 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
1028
1028
al, right->base .loc , right, ASR::cast_kindType::RealToReal,
1029
1029
left_type, nullptr ));
1030
1030
}
1031
+ } else if (ASRUtils::is_complex (*left_type) && ASRUtils::is_complex (*right_type)) {
1032
+ bool is_l64 = ASR::down_cast<ASR::Complex_t>(left_type)->m_kind == 8 ;
1033
+ bool is_r64 = ASR::down_cast<ASR::Complex_t>(right_type)->m_kind == 8 ;
1034
+ if ((is_assign && (is_l64 != is_r64)) || (is_l64 && !is_r64)) {
1035
+ return ASR::down_cast<ASR::expr_t >(ASR::make_ImplicitCast_t (
1036
+ al, right->base .loc , right, ASR::cast_kindType::ComplexToComplex,
1037
+ left_type, nullptr ));
1038
+ }
1031
1039
} else if (!is_assign && ASRUtils::is_real (*left_type) && ASRUtils::is_integer (*right_type)) {
1032
1040
return ASR::down_cast<ASR::expr_t >(ASR::make_ImplicitCast_t (
1033
1041
al, right->base .loc , right, ASR::cast_kindType::IntegerToReal,
1034
1042
left_type, nullptr ));
1035
1043
} else if (is_assign && ASRUtils::is_real (*left_type) && ASRUtils::is_integer (*right_type)) {
1036
1044
throw SemanticError (" Assigning integer to float is not supported" ,
1037
1045
right->base .loc );
1046
+ } else if (is_assign && ASRUtils::is_complex (*left_type) && !ASRUtils::is_complex (*right_type)) {
1047
+ throw SemanticError (" Assigning non-complex to complex is not supported" ,
1048
+ right->base .loc );
1049
+ } else if (!is_assign && ASRUtils::is_complex (*left_type) && !ASRUtils::is_complex (*right_type)) {
1050
+ if (ASRUtils::is_real (*right_type)) {
1051
+ return ASR::down_cast<ASR::expr_t >(ASR::make_ImplicitCast_t (
1052
+ al, right->base .loc , right, ASR::cast_kindType::RealToComplex,
1053
+ left_type, nullptr ));
1054
+ } else if (ASRUtils::is_integer (*right_type)) {
1055
+ return ASR::down_cast<ASR::expr_t >(ASR::make_ImplicitCast_t (
1056
+ al, right->base .loc , right, ASR::cast_kindType::IntegerToComplex,
1057
+ left_type, nullptr ));
1058
+ } else {
1059
+ std::string rtype = ASRUtils::type_to_str (right_type);
1060
+ throw SemanticError (" Casting " + rtype + " to complex is not Implemented" ,
1061
+ right->base .loc );
1062
+ }
1038
1063
}
1039
1064
return right;
1040
1065
}
@@ -1406,8 +1431,10 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
1406
1431
value));
1407
1432
}
1408
1433
}
1409
- } else if ((ASRUtils::is_integer (*left_type) || ASRUtils::is_real (*left_type)) &&
1410
- (ASRUtils::is_integer (*right_type) || ASRUtils::is_real (*right_type)) ){
1434
+ } else if ((ASRUtils::is_integer (*left_type) || ASRUtils::is_real (*left_type) ||
1435
+ ASRUtils::is_complex (*left_type)) &&
1436
+ (ASRUtils::is_integer (*right_type) || ASRUtils::is_real (*right_type) ||
1437
+ ASRUtils::is_complex (*right_type))) {
1411
1438
left = implicitcast_helper (ASRUtils::expr_type (right), left);
1412
1439
right = implicitcast_helper (ASRUtils::expr_type (left), right);
1413
1440
dest_type = ASRUtils::expr_type (left);
@@ -2326,7 +2353,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
2326
2353
if (ASR::is_a<ASR::ExternalSymbol_t>(*stemp)) {
2327
2354
local_sym = std::string (p->m_name ) + " @" + local_sym;
2328
2355
}
2329
-
2356
+
2330
2357
SymbolTable *symtab = current_scope;
2331
2358
while (symtab->parent != nullptr && symtab->scope .find (local_sym) == symtab->scope .end ()) {
2332
2359
symtab = symtab->parent ;
0 commit comments