Skip to content

Commit 36cd4a9

Browse files
committed
Revert "Set dest_type unconditionally"
This reverts commit 532893d.
1 parent 532893d commit 36cd4a9

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,8 +2079,6 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
20792079
} else if ((right_is_int || left_is_int) && op == ASR::binopType::Mul) {
20802080
// string repeat
20812081
int64_t left_int = 0, right_int = 0, dest_len = 0;
2082-
dest_type = ASRUtils::TYPE(ASR::make_Character_t(al,
2083-
loc, 1, 1, nullptr));
20842082
if (right_is_int && ASRUtils::expr_value(right) != nullptr) {
20852083
ASR::Character_t *left_type2 = ASR::down_cast<ASR::Character_t>(
20862084
ASRUtils::type_get_past_array(left_type));
@@ -2089,6 +2087,9 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
20892087
ASRUtils::expr_value(right))->m_n;
20902088
dest_len = left_type2->m_len * right_int;
20912089
if (dest_len < 0) dest_len = 0;
2090+
dest_type = ASR::down_cast<ASR::ttype_t>(
2091+
ASR::make_Character_t(al, loc, left_type2->m_kind,
2092+
dest_len, nullptr));
20922093
} else if (left_is_int && ASRUtils::expr_value(left) != nullptr) {
20932094
ASR::Character_t *right_type2 = ASR::down_cast<ASR::Character_t>(
20942095
ASRUtils::type_get_past_array(right_type));
@@ -2097,6 +2098,13 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
20972098
ASRUtils::expr_value(left))->m_n;
20982099
dest_len = right_type2->m_len * left_int;
20992100
if (dest_len < 0) dest_len = 0;
2101+
dest_type = ASR::down_cast<ASR::ttype_t>(
2102+
ASR::make_Character_t(al, loc, right_type2->m_kind,
2103+
dest_len, nullptr));
2104+
} else if ((left_is_int && ASRUtils::expr_value(left) == nullptr)
2105+
|| (right_is_int && ASRUtils::expr_value(right) == nullptr)) {
2106+
dest_type = ASRUtils::TYPE(ASR::make_Character_t(al,
2107+
loc, 1, 1, nullptr));
21002108
}
21012109

21022110
if (ASRUtils::expr_value(left) != nullptr && ASRUtils::expr_value(right) != nullptr) {

0 commit comments

Comments
 (0)