diff --git a/src/typechecker/typechecker.cpp b/src/typechecker/typechecker.cpp index 56dff04..9af2545 100644 --- a/src/typechecker/typechecker.cpp +++ b/src/typechecker/typechecker.cpp @@ -408,6 +408,8 @@ namespace Solstice { auto& function = functions[*name]; + node.ptype.possiblities.clear(); + node.ptype.unknownType = false; std::vector args; // narrow types based on function @@ -434,8 +436,8 @@ namespace Solstice { throw std::runtime_error("no matching overload found for function " + *name); } child.ptype.possiblities = newTypes; - - } + } + variables[*id].possiblities = child.ptype.possiblities; } args.push_back(child.ptype); } @@ -443,19 +445,18 @@ namespace Solstice { // get all possible combinations auto sets = doCartesianProductOnTypeSets(args); - bool found = false; for (const auto& set : sets) { if (function.returnTypes.find(set) != function.returnTypes.end()) { - if (found) { - throw std::runtime_error("conflicting function definitions"); - } - found = true; - node.ptype = {{function.returnTypes[set]}}; + node.ptype.possiblities.insert(function.returnTypes[set]); } } - if (!found) { + + if (node.ptype.possiblities.empty()) { throw std::runtime_error("no matching overload found for function " + *name); } + if (node.ptype.possiblities.size() > 1) { + node.ptype.unknownType = true; + } } void TypeChecker::checkFunctionCallNodeType(Node& node) {