diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index ea416e764b..3a325386a8 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -828,6 +828,7 @@ RUN(NAME callback_03 LABELS cpython llvm llvm_jit c) RUN(NAME lambda_01 LABELS cpython llvm llvm_jit) RUN(NAME c_mangling LABELS cpython llvm llvm_jit c) +RUN(NAME class_01 LABELS cpython llvm llvm_jit) # callback_04 is to test emulation. So just run with cpython RUN(NAME callback_04 IMPORT_PATH .. LABELS cpython) diff --git a/integration_tests/class_01.py b/integration_tests/class_01.py new file mode 100644 index 0000000000..f23e1b7076 --- /dev/null +++ b/integration_tests/class_01.py @@ -0,0 +1,28 @@ +from lpython import i32,i64 + +def fn_2(): + print("Inside fn_2") + return + +class Test: + mem : i64 = i64(5) + s : str = "abc" + def fn_1(): + print("Inside fn_1") + print("fn_2 called") + fn_2() + print("fn_3 called") + Test.fn_3() + return + def fn_3(): + print("Inside fn_3") + +def main(): + t: Test = Test() + print(t.mem) + assert t.mem == i64(5) + print(t.s) + assert t.s == "abc" + Test.fn_1() + +main() \ No newline at end of file diff --git a/src/libasr/asr_verify.cpp b/src/libasr/asr_verify.cpp index 19adc83ae8..1ed1d0d303 100644 --- a/src/libasr/asr_verify.cpp +++ b/src/libasr/asr_verify.cpp @@ -529,11 +529,13 @@ class VerifyVisitor : public BaseWalkVisitor ASR::is_a(*a.second) || ASR::is_a(*a.second) || ASR::is_a(*a.second) || - ASR::is_a(*a.second) ) { + ASR::is_a(*a.second) || + ASR::is_a(*a.second)) { continue ; } // TODO: Uncomment the following line // ASR::ttype_t* var_type = ASRUtils::extract_type(ASRUtils::symbol_type(a.second)); + ASR::ttype_t* var_type = ASRUtils::type_get_past_pointer(ASRUtils::symbol_type(a.second)); char* aggregate_type_name = nullptr; ASR::symbol_t* sym = nullptr; diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 61e54152aa..e12d02be09 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -3014,6 +3014,30 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } } + void visit_StructType(const ASR::StructType_t &x){ + SymbolTable *current_scope_copy = current_scope; + current_scope = x.m_symtab; + for (auto &item : x.m_symtab->get_scope()){ + if (is_a(*item.second)){ + ASR::Function_t *v = down_cast(item.second); + instantiate_function(*v); + } + } + current_scope = current_scope_copy; + } + + void make_struct_f_def(const ASR::StructType_t &x){ + SymbolTable *current_scope_copy = current_scope; + current_scope = x.m_symtab; + for (auto &item : x.m_symtab->get_scope()){ + if (is_a(*item.second)){ + ASR::Function_t *v = down_cast(item.second); + visit_Function(*v); + } + } + current_scope = current_scope_copy; + } + void start_module_init_function_prototype(const ASR::Module_t &x) { uint32_t h = get_hash((ASR::asr_t*)&x); llvm::FunctionType *function_type = llvm::FunctionType::get( @@ -3055,6 +3079,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } else if (is_a(*item.second)) { ASR::EnumType_t *et = down_cast(item.second); visit_EnumType(*et); + } else if (is_a(*item.second)) { + mangle_prefix = ""; + ASR::StructType_t *st = down_cast(item.second); + visit_StructType(*st); + mangle_prefix = "__module_" + std::string(x.m_name) + "_"; } } finish_module_init_function_prototype(x); @@ -4048,6 +4077,9 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor if (is_a(*item.second)) { ASR::Function_t *s = ASR::down_cast(item.second); visit_Function(*s); + }else if(is_a(*item.second)) { + ASR::StructType_t *st = down_cast(item.second); + make_struct_f_def(*st); } } } diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index f7067e3e82..47218dbad7 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -2493,13 +2493,11 @@ class CommonVisitor : public AST::BaseVisitor { return false; } - bool is_dataclass(AST::expr_t** decorators, size_t n, + void get_alignment(AST::expr_t** decorators, size_t n, ASR::expr_t*& aligned_expr, bool& is_packed) { - bool is_dataclass_ = false; for( size_t i = 0; i < n; i++ ) { if( AST::is_a(*decorators[i]) ) { AST::Name_t* dc_name = AST::down_cast(decorators[i]); - is_dataclass_ = std::string(dc_name->m_id) == "dataclass"; is_packed = is_packed || std::string(dc_name->m_id) == "packed"; } else if( AST::is_a(*decorators[i]) ) { AST::Call_t* dc_call = AST::down_cast(decorators[i]); @@ -2532,7 +2530,7 @@ class CommonVisitor : public AST::BaseVisitor { } } - return is_dataclass_; + return; } bool is_enum(AST::expr_t** bases, size_t n) { @@ -2870,9 +2868,10 @@ class CommonVisitor : public AST::BaseVisitor { if (is_const) { storage_type = ASR::storage_typeType::Parameter; } - - create_add_variable_to_scope(var_name, type, - x.base.base.loc, abi, storage_type); + if( !(inside_struct && current_scope->resolve_symbol(var_name)) ){ + create_add_variable_to_scope(var_name, type, + x.base.base.loc, abi, storage_type); + } ASR::expr_t* assign_asr_target_copy = assign_asr_target; this->visit_expr(*x.m_target); @@ -2926,7 +2925,29 @@ class CommonVisitor : public AST::BaseVisitor { void visit_ClassMembers(const AST::ClassDef_t& x, Vec& member_names, SetChar& struct_dependencies, Vec &member_init, - bool is_enum_scope=false, ASR::abiType abi=ASR::abiType::Source) { + bool is_enum_scope=false, ASR::abiType abi=ASR::abiType::Source, + bool is_generating_body = false) { + if(is_generating_body && !is_enum_scope){ + for( size_t i = 0; i < x.n_body; i++ ){ + if ( AST::is_a(*x.m_body[i]) ) + //generating function body + this->visit_stmt(*x.m_body[i]); + if (AST::is_a(*x.m_body[i])) { + //Add initializers to the AnnAssign + AST::AnnAssign_t* ann_assign = AST::down_cast(x.m_body[i]); + AST::Name_t *n = AST::down_cast(ann_assign->m_target); + std::string var_name = n->m_id; + ASR::expr_t* init_expr = nullptr; + visit_AnnAssignUtil(*ann_assign, var_name, init_expr, false, abi, true); + ASR::symbol_t* var_sym = current_scope->resolve_symbol(var_name); + ASR::call_arg_t c_arg; + c_arg.loc = var_sym->base.loc; + c_arg.m_value = init_expr; + member_init.push_back(al, c_arg); + } + } + return; + } int64_t prev_value = 1; for( size_t i = 0; i < x.n_body; i++ ) { if (AST::is_a(*x.m_body[i])) { @@ -2939,77 +2960,80 @@ class CommonVisitor : public AST::BaseVisitor { } throw SemanticError("Only doc strings and const ellipsis allowed as expressions inside class", expr->base.base.loc); } else if( AST::is_a(*x.m_body[i]) ) { - visit_ClassDef(*AST::down_cast(x.m_body[i])); + visit_ClassDef(*AST::down_cast(x.m_body[i])); continue; } else if ( AST::is_a(*x.m_body[i]) ) { - throw SemanticError("Struct member functions are not supported", x.m_body[i]->base.loc); + this->visit_stmt(*x.m_body[i]); + continue; } else if (AST::is_a(*x.m_body[i])) { continue; - } else if (!AST::is_a(*x.m_body[i])) { - throw SemanticError("AnnAssign expected inside struct", x.m_body[i]->base.loc); - } - AST::AnnAssign_t* ann_assign = AST::down_cast(x.m_body[i]); - if (!AST::is_a(*ann_assign->m_target)) { - throw SemanticError("Only Name supported as target in AnnAssign inside struct", x.m_body[i]->base.loc); - } - AST::Name_t *n = AST::down_cast(ann_assign->m_target); - std::string var_name = n->m_id; - ASR::expr_t* init_expr = nullptr; - if( is_enum_scope ) { - ASR::ttype_t* i64_type = ASRUtils::TYPE(ASR::make_Integer_t(al, x.base.base.loc, 8)); - init_expr = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, x.base.base.loc, -1, i64_type)); - } - visit_AnnAssignUtil(*ann_assign, var_name, init_expr, false, abi, true); - ASR::symbol_t* var_sym = current_scope->resolve_symbol(var_name); - ASR::call_arg_t c_arg; - c_arg.loc = var_sym->base.loc; - c_arg.m_value = init_expr; - member_init.push_back(al, c_arg); - if( is_enum_scope ) { - if( AST::is_a(*ann_assign->m_value) ) { - AST::Call_t* auto_call_cand = AST::down_cast(ann_assign->m_value); - if( AST::is_a(*auto_call_cand->m_func) ) { - AST::Name_t* func = AST::down_cast(auto_call_cand->m_func); - std::string func_name = func->m_id; - if( func_name == "auto" ) { - ASR::ttype_t* int_type = ASRUtils::symbol_type(var_sym); - init_expr = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, - auto_call_cand->base.base.loc, prev_value, int_type)); - prev_value += 1; + } else if (AST::is_a(*x.m_body[i])) { + AST::AnnAssign_t* ann_assign = AST::down_cast(x.m_body[i]); + if (!AST::is_a(*ann_assign->m_target)) { + throw SemanticError("Only Name supported as target in AnnAssign inside struct", x.m_body[i]->base.loc); + } + AST::Name_t *n = AST::down_cast(ann_assign->m_target); + std::string var_name = n->m_id; + ASR::expr_t* init_expr = nullptr; + if( is_enum_scope ) { + ASR::ttype_t* i64_type = ASRUtils::TYPE(ASR::make_Integer_t(al, x.base.base.loc, 8)); + init_expr = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, x.base.base.loc, -1, i64_type)); + } + visit_AnnAssignUtil(*ann_assign, var_name, init_expr, false, abi, true); + ASR::symbol_t* var_sym = current_scope->resolve_symbol(var_name); + ASR::call_arg_t c_arg; + c_arg.loc = var_sym->base.loc; + c_arg.m_value = init_expr; + member_init.push_back(al, c_arg); + if( is_enum_scope ) { + if( AST::is_a(*ann_assign->m_value) ) { + AST::Call_t* auto_call_cand = AST::down_cast(ann_assign->m_value); + if( AST::is_a(*auto_call_cand->m_func) ) { + AST::Name_t* func = AST::down_cast(auto_call_cand->m_func); + std::string func_name = func->m_id; + if( func_name == "auto" ) { + ASR::ttype_t* int_type = ASRUtils::symbol_type(var_sym); + init_expr = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, + auto_call_cand->base.base.loc, prev_value, int_type)); + prev_value += 1; + } } + } else { + this->visit_expr(*ann_assign->m_value); + ASR::expr_t* enum_value = ASRUtils::expr_value(ASRUtils::EXPR(tmp)); + LCOMPILERS_ASSERT(ASRUtils::is_value_constant(enum_value)); + ASRUtils::extract_value(enum_value, prev_value); + prev_value += 1; + init_expr = enum_value; } } else { - this->visit_expr(*ann_assign->m_value); - ASR::expr_t* enum_value = ASRUtils::expr_value(ASRUtils::EXPR(tmp)); - LCOMPILERS_ASSERT(ASRUtils::is_value_constant(enum_value)); - ASRUtils::extract_value(enum_value, prev_value); - prev_value += 1; - init_expr = enum_value; - } - } else { - init_expr = nullptr; - } - if( ASR::is_a(*var_sym) ) { - ASR::Variable_t* variable = ASR::down_cast(var_sym); - variable->m_symbolic_value = init_expr; - } - ASR::ttype_t* var_type = ASRUtils::type_get_past_pointer(ASRUtils::symbol_type(var_sym)); - char* aggregate_type_name = nullptr; - if( ASR::is_a(*var_type) ) { - aggregate_type_name = ASRUtils::symbol_name( - ASR::down_cast(var_type)->m_derived_type); - } else if( ASR::is_a(*var_type) ) { - aggregate_type_name = ASRUtils::symbol_name( - ASR::down_cast(var_type)->m_enum_type); - } else if( ASR::is_a(*var_type) ) { - aggregate_type_name = ASRUtils::symbol_name( - ASR::down_cast(var_type)->m_union_type); + init_expr = nullptr; + } + if( ASR::is_a(*var_sym) ) { + ASR::Variable_t* variable = ASR::down_cast(var_sym); + variable->m_symbolic_value = init_expr; + } + ASR::ttype_t* var_type = ASRUtils::type_get_past_pointer(ASRUtils::symbol_type(var_sym)); + char* aggregate_type_name = nullptr; + if( ASR::is_a(*var_type) ) { + aggregate_type_name = ASRUtils::symbol_name( + ASR::down_cast(var_type)->m_derived_type); + } else if( ASR::is_a(*var_type) ) { + aggregate_type_name = ASRUtils::symbol_name( + ASR::down_cast(var_type)->m_enum_type); + } else if( ASR::is_a(*var_type) ) { + aggregate_type_name = ASRUtils::symbol_name( + ASR::down_cast(var_type)->m_union_type); + } + if( aggregate_type_name && + !current_scope->get_symbol(std::string(aggregate_type_name)) ) { + struct_dependencies.push_back(al, aggregate_type_name); + } + member_names.push_back(al, n->m_id); } - if( aggregate_type_name && - !current_scope->get_symbol(std::string(aggregate_type_name)) ) { - struct_dependencies.push_back(al, aggregate_type_name); + else { + throw SemanticError("AnnAssign or Function def expected inside struct", x.m_body[i]->base.loc); } - member_names.push_back(al, n->m_id); } } @@ -3030,6 +3054,7 @@ class CommonVisitor : public AST::BaseVisitor { void visit_ClassDef(const AST::ClassDef_t& x) { std::string x_m_name = x.m_name; + bool is_generating_body = false; if( is_enum(x.m_bases, x.n_bases) ) { if( current_scope->resolve_symbol(x_m_name) ) { return ; @@ -3150,19 +3175,21 @@ class CommonVisitor : public AST::BaseVisitor { } ASR::expr_t* algined_expr = nullptr; bool is_packed = false; - if( !is_dataclass(x.m_decorator_list, x.n_decorator_list, - algined_expr, is_packed) ) { - throw SemanticError("Only dataclass-decorated classes and Enum subclasses are supported.", - x.base.base.loc); - } - + get_alignment(x.m_decorator_list, x.n_decorator_list, algined_expr, is_packed); if( x.n_bases > 0 ) { throw SemanticError("Inheritance in classes isn't supported yet.", x.base.base.loc); } - SymbolTable *parent_scope = current_scope; - current_scope = al.make_new(parent_scope); + ASR::symbol_t* clss_sym = current_scope->get_symbol(x_m_name); + ASR::StructType_t* clss = nullptr; + if( clss_sym != nullptr ){ + clss = ASR::down_cast(clss_sym); + current_scope = clss->m_symtab; + is_generating_body = true; + }else{ + current_scope = al.make_new(parent_scope); + } Vec member_names; Vec member_init; member_names.reserve(al, x.n_body); @@ -3173,8 +3200,7 @@ class CommonVisitor : public AST::BaseVisitor { if( is_bindc_class(x.m_decorator_list, x.n_decorator_list) ) { class_abi = ASR::abiType::BindC; } - visit_ClassMembers(x, member_names, struct_dependencies, member_init, false, class_abi); - LCOMPILERS_ASSERT(member_init.size() == member_names.size()); + visit_ClassMembers(x, member_names, struct_dependencies, member_init, false, class_abi,is_generating_body); ASR::symbol_t* class_type = ASR::down_cast(ASR::make_StructType_t(al, x.base.base.loc, current_scope, x.m_name, struct_dependencies.p, struct_dependencies.size(), @@ -3188,6 +3214,8 @@ class CommonVisitor : public AST::BaseVisitor { ASR::StructType_t *st = ASR::down_cast(sym); st->m_initializers = member_init.p; st->n_initializers = member_init.size(); + clss->m_symtab->asr_owner = &clss_sym->base; + return; } else { current_scope->add_symbol(x_m_name, class_type); } diff --git a/tests/reference/asr-intent_01-66824bc.json b/tests/reference/asr-intent_01-66824bc.json index c981754321..1c060f855d 100644 --- a/tests/reference/asr-intent_01-66824bc.json +++ b/tests/reference/asr-intent_01-66824bc.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-intent_01-66824bc.stdout", - "stdout_hash": "415fb57ee7c986fc49e7c0801edae4e37d6ea06143d27a998c50ab5c", + "stdout_hash": "b4d6158df60118b1a4c88f675262373b18c3ebe073ac2d0761ece543", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-intent_01-66824bc.stdout b/tests/reference/asr-intent_01-66824bc.stdout index d668611200..0cd3dbd294 100644 --- a/tests/reference/asr-intent_01-66824bc.stdout +++ b/tests/reference/asr-intent_01-66824bc.stdout @@ -171,7 +171,7 @@ main_program: (Program (SymbolTable - 6 + 5 { }) diff --git a/tests/reference/asr-structs_01-0893e35.stdout b/tests/reference/asr-structs_01-0893e35.stdout new file mode 100644 index 0000000000..fe91a8a77e --- /dev/null +++ b/tests/reference/asr-structs_01-0893e35.stdout @@ -0,0 +1,116 @@ +(TranslationUnit + (SymbolTable + 1 + { + __main__: + (Module + (SymbolTable + 2 + { + PackedStruct: + (StructType + (SymbolTable + 3 + { + Data1: + (Variable + 3 + Data1 + [] + Local + () + () + Default + (Integer 1) + () + Source + Public + Required + .false. + ), + Data2: + (Variable + 3 + Data2 + [] + Local + () + () + Default + (Integer 4) + () + Source + Public + Required + .false. + ), + Data3: + (Variable + 3 + Data3 + [] + Local + () + () + Default + (Integer 1) + () + Source + Public + Required + .false. + ), + Data4: + (Variable + 3 + Data4 + [] + Local + () + () + Default + (Integer 1) + () + Source + Public + Required + .false. + ) + }) + PackedStruct + [] + [Data1 + Data2 + Data3 + Data4] + Source + Public + .false. + .false. + [(()) + (()) + (()) + (())] + () + () + ) + }) + __main__ + [] + .false. + .false. + ), + main_program: + (Program + (SymbolTable + 4 + { + + }) + main_program + [] + [] + ) + }) + [] +) diff --git a/tests/reference/asr-structs_01-66dc2c9.json b/tests/reference/asr-structs_01-66dc2c9.json index ab164948f8..03f10e8011 100644 --- a/tests/reference/asr-structs_01-66dc2c9.json +++ b/tests/reference/asr-structs_01-66dc2c9.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-structs_01-66dc2c9.stdout", - "stdout_hash": "5a32fdd6e6d78976f4d3effbdf4ab79c614eb664a4fd92967ff5d7d7", + "stdout_hash": "3707ab1ee9836ed08cf219d72023f5927694523166b47faf93ed1bc4", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-structs_01-66dc2c9.stdout b/tests/reference/asr-structs_01-66dc2c9.stdout index afebbfd171..98f9e178f5 100644 --- a/tests/reference/asr-structs_01-66dc2c9.stdout +++ b/tests/reference/asr-structs_01-66dc2c9.stdout @@ -61,7 +61,7 @@ __main__global_stmts: (Function (SymbolTable - 6 + 5 { }) @@ -163,11 +163,11 @@ main_program: (Program (SymbolTable - 7 + 6 { __main__global_stmts: (ExternalSymbol - 7 + 6 __main__global_stmts 2 __main__global_stmts __main__ @@ -179,7 +179,7 @@ main_program [__main__] [(SubroutineCall - 7 __main__global_stmts + 6 __main__global_stmts 2 __main__global_stmts [] () diff --git a/tests/reference/asr-structs_01-be14d49.json b/tests/reference/asr-structs_01-be14d49.json index f149ce9e6e..136a469295 100644 --- a/tests/reference/asr-structs_01-be14d49.json +++ b/tests/reference/asr-structs_01-be14d49.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-structs_01-be14d49.stdout", - "stdout_hash": "6ff17e00a05b231e19396a82ff1a25538d74f39f4df7ccc44abf592c", + "stdout_hash": "b90bd9634c5634385cc255dc7d6540875c22968ef123777394d4c26e", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-structs_01-be14d49.stdout b/tests/reference/asr-structs_01-be14d49.stdout index e96c8d99c9..7c3906a437 100644 --- a/tests/reference/asr-structs_01-be14d49.stdout +++ b/tests/reference/asr-structs_01-be14d49.stdout @@ -61,7 +61,7 @@ __main__global_stmts: (Function (SymbolTable - 8 + 7 { }) @@ -506,11 +506,11 @@ main_program: (Program (SymbolTable - 9 + 8 { __main__global_stmts: (ExternalSymbol - 9 + 8 __main__global_stmts 2 __main__global_stmts __main__ @@ -522,7 +522,7 @@ main_program [__main__] [(SubroutineCall - 9 __main__global_stmts + 8 __main__global_stmts 2 __main__global_stmts [] () diff --git a/tests/reference/asr-structs_02-2ab459a.json b/tests/reference/asr-structs_02-2ab459a.json index 298b5bc8a2..85dd21b6ea 100644 --- a/tests/reference/asr-structs_02-2ab459a.json +++ b/tests/reference/asr-structs_02-2ab459a.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-structs_02-2ab459a.stdout", - "stdout_hash": "cc9088a5c112c3dd9820ddfb3695cc301e46d853c4f4634fcdb457b6", + "stdout_hash": "545b53fda59f078d8aeebb4577b6e7dc78699aa576d6ffbc594f5e91", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-structs_02-2ab459a.stdout b/tests/reference/asr-structs_02-2ab459a.stdout index 00933ce63c..36acbf605a 100644 --- a/tests/reference/asr-structs_02-2ab459a.stdout +++ b/tests/reference/asr-structs_02-2ab459a.stdout @@ -61,7 +61,7 @@ __main__global_stmts: (Function (SymbolTable - 7 + 6 { }) @@ -375,11 +375,11 @@ main_program: (Program (SymbolTable - 8 + 7 { __main__global_stmts: (ExternalSymbol - 8 + 7 __main__global_stmts 2 __main__global_stmts __main__ @@ -391,7 +391,7 @@ main_program [__main__] [(SubroutineCall - 8 __main__global_stmts + 7 __main__global_stmts 2 __main__global_stmts [] () diff --git a/tests/reference/asr-structs_03-0cef911.json b/tests/reference/asr-structs_03-0cef911.json index 4cff33ed98..606010d198 100644 --- a/tests/reference/asr-structs_03-0cef911.json +++ b/tests/reference/asr-structs_03-0cef911.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-structs_03-0cef911.stdout", - "stdout_hash": "86f4e5e4f8a98068919cc24f5e1add31777cbf511dcc6164587c58e3", + "stdout_hash": "6add835ab5c6038f3eea263aab954964c8cc5f8157ff3291551f0e29", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-structs_03-0cef911.stdout b/tests/reference/asr-structs_03-0cef911.stdout index 5f268f4dde..72f1b2e8b4 100644 --- a/tests/reference/asr-structs_03-0cef911.stdout +++ b/tests/reference/asr-structs_03-0cef911.stdout @@ -61,7 +61,7 @@ __main__global_stmts: (Function (SymbolTable - 7 + 6 { }) @@ -355,11 +355,11 @@ main_program: (Program (SymbolTable - 8 + 7 { __main__global_stmts: (ExternalSymbol - 8 + 7 __main__global_stmts 2 __main__global_stmts __main__ @@ -371,7 +371,7 @@ main_program [__main__] [(SubroutineCall - 8 __main__global_stmts + 7 __main__global_stmts 2 __main__global_stmts [] () diff --git a/tests/reference/asr-structs_04-387747b.json b/tests/reference/asr-structs_04-387747b.json index d0f8cbec18..dce20d6202 100644 --- a/tests/reference/asr-structs_04-387747b.json +++ b/tests/reference/asr-structs_04-387747b.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-structs_04-387747b.stdout", - "stdout_hash": "27f6a0c804ed3cea5368c4bec54cb4ea35c60215f354d0d91bc24e89", + "stdout_hash": "5da7fcbfef353f9e0aa676ae59874a5d7ddafd30069c633e3c12db7b", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-structs_04-387747b.stdout b/tests/reference/asr-structs_04-387747b.stdout index 32225f2ccf..14a40bcbaf 100644 --- a/tests/reference/asr-structs_04-387747b.stdout +++ b/tests/reference/asr-structs_04-387747b.stdout @@ -133,7 +133,7 @@ __main__global_stmts: (Function (SymbolTable - 9 + 7 { }) @@ -620,11 +620,11 @@ main_program: (Program (SymbolTable - 10 + 8 { __main__global_stmts: (ExternalSymbol - 10 + 8 __main__global_stmts 2 __main__global_stmts __main__ @@ -636,7 +636,7 @@ main_program [__main__] [(SubroutineCall - 10 __main__global_stmts + 8 __main__global_stmts 2 __main__global_stmts [] () diff --git a/tests/reference/asr-structs_05-fa98307.json b/tests/reference/asr-structs_05-fa98307.json index cc000e12a0..af0869748b 100644 --- a/tests/reference/asr-structs_05-fa98307.json +++ b/tests/reference/asr-structs_05-fa98307.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-structs_05-fa98307.stdout", - "stdout_hash": "46a6d4fc967a5081b9d2df3936f9a3696cc8383bd140ee0cb37c5e75", + "stdout_hash": "28bf4c643bcd85ad31e0e350e74f557ca56f7d4f69a69b7d9246f9e7", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-structs_05-fa98307.stdout b/tests/reference/asr-structs_05-fa98307.stdout index 1ef54ab37e..f3d1b8675f 100644 --- a/tests/reference/asr-structs_05-fa98307.stdout +++ b/tests/reference/asr-structs_05-fa98307.stdout @@ -151,7 +151,7 @@ __main__global_stmts: (Function (SymbolTable - 232 + 231 { }) @@ -1446,11 +1446,11 @@ main_program: (Program (SymbolTable - 233 + 232 { __main__global_stmts: (ExternalSymbol - 233 + 232 __main__global_stmts 2 __main__global_stmts __main__ @@ -1462,7 +1462,7 @@ main_program [__main__] [(SubroutineCall - 233 __main__global_stmts + 232 __main__global_stmts 2 __main__global_stmts [] () diff --git a/tests/reference/asr-structs_10-cb8a283.json b/tests/reference/asr-structs_10-cb8a283.json index 6420f7ba94..d59834dcb5 100644 --- a/tests/reference/asr-structs_10-cb8a283.json +++ b/tests/reference/asr-structs_10-cb8a283.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "asr-structs_10-cb8a283.stderr", - "stderr_hash": "2b88127fdbc0c9e3798569cdfa4ef5745d6fce6aeba8fc3f6a1ace9f", + "stderr_hash": "986a1260291bbe43df27d67d801f490853aca9745c2dcf67f7619814", "returncode": 2 } \ No newline at end of file diff --git a/tests/reference/asr-structs_10-cb8a283.stderr b/tests/reference/asr-structs_10-cb8a283.stderr index 757e06a54e..2112ad6a59 100644 --- a/tests/reference/asr-structs_10-cb8a283.stderr +++ b/tests/reference/asr-structs_10-cb8a283.stderr @@ -1,9 +1,5 @@ -semantic error: Struct member functions are not supported - --> tests/errors/structs_10.py:7:5 - 8:24 +semantic error: The type 'StringIO' is undeclared. + --> tests/errors/structs_10.py:7:25 | -7 | def print_len(self: StringIO): - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^... -... - | -8 | print(self._len) - | ...^^^^^^^^^^^^^^^^^^^^^^^^ +7 | def print_len(self: StringIO): + | ^^^^^^^^ diff --git a/tests/reference/asr-structs_16-44de89a.json b/tests/reference/asr-structs_16-44de89a.json index 2710b9ad8a..4b1e0512b3 100644 --- a/tests/reference/asr-structs_16-44de89a.json +++ b/tests/reference/asr-structs_16-44de89a.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-structs_16-44de89a.stdout", - "stdout_hash": "65cfcaf1a3de5bfe7720be9983c0a9ad22d877701f1375eead4ca4b1", + "stdout_hash": "ca24d8b066ba586afc769b2162a90d810050b487511cc79a9977b8c0", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-structs_16-44de89a.stdout b/tests/reference/asr-structs_16-44de89a.stdout index b98dbfb8e1..e5d6197044 100644 --- a/tests/reference/asr-structs_16-44de89a.stdout +++ b/tests/reference/asr-structs_16-44de89a.stdout @@ -111,7 +111,7 @@ __main__global_stmts: (Function (SymbolTable - 8 + 6 { }) @@ -300,11 +300,11 @@ main_program: (Program (SymbolTable - 9 + 7 { __main__global_stmts: (ExternalSymbol - 9 + 7 __main__global_stmts 2 __main__global_stmts __main__ @@ -316,7 +316,7 @@ main_program [__main__] [(SubroutineCall - 9 __main__global_stmts + 7 __main__global_stmts 2 __main__global_stmts [] () diff --git a/tests/reference/pass_class_constructor-structs_16-5e3508f.json b/tests/reference/pass_class_constructor-structs_16-5e3508f.json index 8204d2a621..73523e1cdc 100644 --- a/tests/reference/pass_class_constructor-structs_16-5e3508f.json +++ b/tests/reference/pass_class_constructor-structs_16-5e3508f.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "pass_class_constructor-structs_16-5e3508f.stdout", - "stdout_hash": "b2d0bddf9e8ba1877d428e44cb6bc2a32bb7d2c9db18a20d649dd7cf", + "stdout_hash": "86e4faac26ee8e3fc3fa45581414fc8c6372bd75c0013c2c2d617766", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/pass_class_constructor-structs_16-5e3508f.stdout b/tests/reference/pass_class_constructor-structs_16-5e3508f.stdout index 7ab18fc44d..f64b6f0f9f 100644 --- a/tests/reference/pass_class_constructor-structs_16-5e3508f.stdout +++ b/tests/reference/pass_class_constructor-structs_16-5e3508f.stdout @@ -111,7 +111,7 @@ __main__global_stmts: (Function (SymbolTable - 8 + 6 { }) @@ -329,11 +329,11 @@ main_program: (Program (SymbolTable - 9 + 7 { __main__global_stmts: (ExternalSymbol - 9 + 7 __main__global_stmts 2 __main__global_stmts __main__ @@ -345,7 +345,7 @@ main_program [__main__] [(SubroutineCall - 9 __main__global_stmts + 7 __main__global_stmts 2 __main__global_stmts [] ()