Problem
The typechecker uses similar but not identical patterns for checking methods on different container types:
- check_list_method in `check_list.cpp`
- check_pair_method in `check_pair.cpp`
- check_tuple_method in `check_tuple.cpp`
- check_channel_method in `check_channel.cpp`
- check_str_method in `check_method_call.cpp`
Each has its own way of looking up method info:
// List uses:
auto method_info = bishop::get_list_method_info(mcall.method_name);
// Str uses:
auto method_info = bishop::get_str_method_info(mcall.method_name);
The argument checking logic is then repeated in each.
Suggested Solution
Create a unified generic method checking helper:
// In a new file: typechecker/check_builtin_method.hpp
struct BuiltinMethodInfo {
vector<string> param_types; // "T" means element type
string return_type; // "T" means element type
bool is_optional_return = false;
};
TypeInfo check_builtin_method(
TypeCheckerState& state,
const MethodCall& mcall,
const string& type_name, // e.g., "List", "Pair"
const string& element_type, // e.g., "int", "str"
const BuiltinMethodInfo& method_info
);
Then each container uses this shared implementation:
TypeInfo check_list_method(...) {
auto info = get_list_method_info(mcall.method_name);
if (!info) { error(...); return unknown; }
return check_builtin_method(state, mcall, "List", element_type, *info);
}
Impact
- Reduces duplication across 5 files
- Consistent error messages
- Easier to add new container types
Problem
The typechecker uses similar but not identical patterns for checking methods on different container types:
Each has its own way of looking up method info:
The argument checking logic is then repeated in each.
Suggested Solution
Create a unified generic method checking helper:
Then each container uses this shared implementation:
Impact