Skip to content

Commit 8a5f6f9

Browse files
Add empty string case to compile time evaluation
1 parent 6c7edc8 commit 8a5f6f9

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/lpython/semantics/python_comptime_eval.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,9 @@ struct PythonIntrinsicProcedures {
661661
ASR::expr_t *arg = args[0];
662662
ASR::ttype_t *arg_type = ASRUtils::expr_type(arg);
663663
std::string val = ASR::down_cast<ASR::StringConstant_t>(arg)->m_s;
664-
val = std::toupper(val[0]);
664+
if (val.size()) {
665+
val[0] = std::toupper(val[0]);
666+
}
665667
ASR::ttype_t *type = ASRUtils::TYPE(ASR::make_Character_t(al, loc,
666668
1, 1, nullptr, nullptr, 0));
667669
ASR::ttype_t *res_type = ASRUtils::TYPE(ASR::make_StringConstant_t(al, loc, s2c(al, ""), type));

src/runtime/lpython_builtin.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,8 @@ def pow(x: i64, y: i64, z: i64) -> i64:
616616

617617
@overload
618618
def _lpython_str_capitalize(x: str) -> str:
619+
if len(x) == 0:
620+
return x
619621
val: i32
620622
val = ord(x[0])
621623
if val >= ord('a') and val <= ord('x'):

0 commit comments

Comments
 (0)