@@ -8790,23 +8790,32 @@ we will have to use something else.
87908790 }
87918791 return ;
87928792 } else if (args.size () > 1 ) {
8793- throw SemanticError (" set() accepts only 1 argument for now, got " +
8793+ throw SemanticError (" set accepts only 1 argument for now, got " +
87948794 std::to_string (args.size ()) + " arguments instead." ,
87958795 x.base .base .loc );
87968796 }
8797+ if ( assign_asr_target == nullptr ) {
8798+ throw SemanticError (" set from list cannot be called without target type for now" , x.base .base .loc );
8799+ }
87978800 ASR::expr_t *arg = args[0 ].m_value ;
87988801 ASR::ttype_t *type = ASRUtils::expr_type (arg);
8799- if (ASR::is_a<ASR::ListConstant_t>(*arg)) {
8800- ASR::ListConstant_t* list = ASR::down_cast<ASR::ListConstant_t>(arg);
8801- ASR::expr_t **m_args = list->m_args ;
8802- size_t n_args = list->n_args ;
8803-
8804- tmp = ASR::make_SetConstant_t (al, x.base .base .loc , m_args, n_args,
8805- ASRUtils::expr_type (assign_asr_target));
8806- return ;
8807- }
8808- throw SemanticError (" set() accepts only list for now, got " +
8802+ if (!ASR::is_a<ASR::ListConstant_t>(*arg)) {
8803+ throw SemanticError (" set accepts only list for now, got " +
88098804 ASRUtils::type_to_str (type) + " type." , x.base .base .loc );
8805+ }
8806+ ASR::ListConstant_t* list = ASR::down_cast<ASR::ListConstant_t>(arg);
8807+ ASR::expr_t **m_args = list->m_args ;
8808+ size_t n_args = list->n_args ;
8809+ ASR::ttype_t * value_type = ASRUtils::get_contained_type (type);
8810+ ASR::ttype_t * target_type = ASRUtils::get_contained_type (ASRUtils::expr_type (assign_asr_target));
8811+ if (!ASRUtils::check_equal_type (target_type, value_type)){
8812+ std::string ltype = ASRUtils::type_to_str_python (target_type);
8813+ std::string rtype = ASRUtils::type_to_str_python (value_type);
8814+ throw SemanticError (" type mismatch ('" + ltype + " ' and '" + rtype + " ')" , x.base .base .loc );
8815+ }
8816+ tmp = ASR::make_SetConstant_t (al, x.base .base .loc , m_args, n_args,
8817+ ASRUtils::expr_type (assign_asr_target));
8818+ return ;
88108819 } else if ( call_name == " deepcopy" ) {
88118820 parse_args (x, args);
88128821 if ( args.size () != 1 ) {
0 commit comments