diff --git a/src/typechecker/typechecker.cpp b/src/typechecker/typechecker.cpp index b94db37..56dff04 100644 --- a/src/typechecker/typechecker.cpp +++ b/src/typechecker/typechecker.cpp @@ -411,8 +411,32 @@ namespace Solstice { std::vector args; // narrow types based on function - for (auto& child : node.children[1].children) { + for (size_t i = 0; i < node.children[1].children.size(); i++) { + auto& child = node.children[1].children[i]; checkNodeType(child); + if (child.ptype.unknownType && child.type == NodeType::Identifier) { + auto id = child.getIdentifier(); + if (!id.has_value()) { + throw std::runtime_error("identifier node does not contain identifier"); + } + // don't bother with checking against other function combinations, the + // part of the function below will deal with that + if (child.ptype.possiblities.empty()) { + child.ptype.possiblities = function.argumentTypes[i].possiblities; + } else { + std::unordered_set newTypes; + for (const auto& type : function.argumentTypes[i].possiblities) { + if (child.ptype.possiblities.find(type) != child.ptype.possiblities.end()) { + newTypes.insert(type); + } + } + if (newTypes.empty()) { + throw std::runtime_error("no matching overload found for function " + *name); + } + child.ptype.possiblities = newTypes; + + } + } args.push_back(child.ptype); }