diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 4632194e50..d1f7dbbb40 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -796,6 +796,7 @@ RUN(NAME generics_array_03 LABELS cpython llvm llvm_jit c) RUN(NAME generics_list_01 LABELS cpython llvm llvm_jit c) RUN(NAME test_statistics_01 LABELS cpython llvm llvm_jit NOFAST) RUN(NAME test_statistics_02 LABELS cpython llvm llvm_jit NOFAST REQ_PY_VER 3.10) +RUN(NAME test_attributes LABELS cpython llvm llvm_jit) RUN(NAME test_str_attributes LABELS cpython llvm llvm_jit c) RUN(NAME kwargs_01 LABELS cpython llvm llvm_jit c NOFAST) RUN(NAME def_func_01 LABELS cpython llvm llvm_jit c) diff --git a/integration_tests/test_attributes.py b/integration_tests/test_attributes.py new file mode 100644 index 0000000000..f42775b678 --- /dev/null +++ b/integration_tests/test_attributes.py @@ -0,0 +1,12 @@ +def test_attributes() -> None: + a: i32 = 10 + assert a.bit_length() == 4 + + b: str = 'abc' + assert b.upper() == 'ABC' + + c: list[i32] = [10, 20, 30] + assert c[0].bit_length() == 4 + assert c.index(10) == 0 + +test_attributes() diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 0adf860653..5a12d1e3f8 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -8040,6 +8040,17 @@ we will have to use something else. } handle_builtin_attribute(dict_expr, at->m_attr, loc, eles); return; + } else if (AST::is_a(*at->m_value)) { + AST::Subscript_t *s = AST::down_cast(at->m_value); + visit_Subscript(*s); + ASR::expr_t *subscript_expr = ASR::down_cast(tmp); + Vec eles; + eles.reserve(al, args.size()); + for (size_t i = 0; i < args.size(); i++) { + eles.push_back(al, args[i].m_value); + } + handle_builtin_attribute(subscript_expr, at->m_attr, loc, eles); + return; } else { throw SemanticError("Only Name type and constant integers supported in Call", loc); }