@@ -24,7 +24,8 @@ struct AttributeHandler {
2424 {" list@pop" , &eval_list_pop},
2525 {" set@add" , &eval_set_add},
2626 {" set@remove" , &eval_set_remove},
27- {" dict@get" , &eval_dict_get}
27+ {" dict@get" , &eval_dict_get},
28+ {" dict@pop" , &eval_dict_pop}
2829 };
2930 }
3031
@@ -269,6 +270,29 @@ struct AttributeHandler {
269270 return make_DictItem_t (al, loc, s, args[0 ], def, value_type);
270271 }
271272
273+ static ASR ::asr_t * eval_dict_pop (ASR ::symbol_t *s, Allocator &al, const Location &loc,
274+ Vec<ASR ::expr_t *> &args, diag::Diagnostics &diag) {
275+ if (args.size () != 1 ) {
276+ throw SemanticError (" 'pop' takes only one argument for now" , loc);
277+ }
278+ ASR ::Variable_t *v = ASR ::down_cast<ASR ::Variable_t>(s);
279+ ASR ::ttype_t *type = v->m_type ;
280+ ASR ::ttype_t *key_type = ASR ::down_cast<ASR ::Dict_t>(type)->m_key_type ;
281+ ASR ::ttype_t *value_type = ASR ::down_cast<ASR ::Dict_t>(type)->m_value_type ;
282+ if (!ASRUtils::check_equal_type (ASRUtils::expr_type (args[0 ]), key_type)) {
283+ std::string ktype = ASRUtils::type_to_str_python (ASRUtils::expr_type (args[0 ]));
284+ std::string totype = ASRUtils::type_to_str_python (key_type);
285+ diag.add (diag::Diagnostic (
286+ " Type mismatch in pop's key value, the types must be compatible" ,
287+ diag::Level::Error, diag::Stage::Semantic, {
288+ diag::Label (" type mismatch (found: '" + ktype + " ', expected: '" + totype + " ')" ,
289+ {args[0 ]->base .loc })
290+ })
291+ );
292+ throw SemanticAbort ();
293+ }
294+ return make_DictPop_t (al, loc, s, args[0 ], value_type, nullptr );
295+ }
272296
273297}; // AttributeHandler
274298
0 commit comments