Skip to content

Commit 6c7edc8

Browse files
Fix compile time evaluation for lower
1 parent 1a5ef6f commit 6c7edc8

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/lpython/semantics/python_comptime_eval.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -670,21 +670,21 @@ struct PythonIntrinsicProcedures {
670670

671671
static ASR::expr_t *eval__lpython_str_lower(Allocator &al, const Location &loc, Vec<ASR::expr_t *> &args) {
672672
LFORTRAN_ASSERT(ASRUtils::all_args_evaluated(args));
673-
if (args.size() != 1) {
674-
throw SemanticError("_lpython_str_lower() takes exactly one arguments (" +
675-
std::to_string(args.size()) + " given)", loc);
673+
if (args.size() != 0) {
674+
throw SemanticError("str.lower() takes no arguments", loc);
676675
}
677-
ASR::expr_t *arg1 = args[0];
678-
ASR::ttype_t *arg1_type = ASRUtils::expr_type(arg1);
679-
if (ASRUtils::is_character(*arg1_type)) {
680-
std::string val = ASR::down_cast<ASR::StringConstant_t>(arg1)->m_s;
681-
ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Character_t(al, loc,
682-
1, 1, nullptr, nullptr, 0));
683-
ASR::ttype_t *res_type = ASRUtils::TYPE(ASR::make_StringConstant_t(al, loc, s2c(al, ""), type));
684-
return ASR::down_cast<ASR::expr_t>(ASR::make_StringConstant_t(al, loc, s2c(al, val), res_type));
685-
} else {
686-
throw SemanticError("Only string from arguments.", loc);
676+
ASR::expr_t *arg = args[0];
677+
ASR::ttype_t *arg_type = ASRUtils::expr_type(arg);
678+
std::string val = ASR::down_cast<ASR::StringConstant_t>(arg)->m_s;
679+
for (auto &i: val) {
680+
if (i >= 'A' && i <= 'Z') {
681+
i = std::tolower(i);
682+
}
687683
}
684+
ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Character_t(al, loc,
685+
1, 1, nullptr, nullptr, 0));
686+
ASR::ttype_t *res_type = ASRUtils::TYPE(ASR::make_StringConstant_t(al, loc, s2c(al, ""), type));
687+
return ASR::down_cast<ASR::expr_t>(ASR::make_StringConstant_t(al, loc, s2c(al, val), res_type));
688688
}
689689

690690

0 commit comments

Comments
 (0)