Changeset acb33f15 for src/ResolvExpr/CandidateFinder.cpp
- Timestamp:
- May 13, 2024, 10:26:52 AM (5 months ago)
- Branches:
- master
- Children:
- 31f4837
- Parents:
- 41c8312
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/CandidateFinder.cpp
r41c8312 racb33f15 906 906 } 907 907 CandidateRef & choice = winners.front(); 908 choice->cost .incSafe();908 choice->cost = Cost::unsafe; 909 909 candidates.emplace_back( std::move(choice) ); 910 910 } … … 955 955 956 956 CandidateFinder funcFinder( context, tenv ); 957 std::string funcName; 957 958 if (auto nameExpr = untypedExpr->func.as<ast::NameExpr>()) { 959 funcName = nameExpr->name; 958 960 auto kind = ast::SymbolTable::getSpecialFunctionKind(nameExpr->name); 959 961 if (kind != ast::SymbolTable::SpecialFunctionKind::NUMBER_OF_KINDS) { … … 1019 1021 CandidateList found; 1020 1022 SemanticErrorException errors; 1023 1021 1024 for ( CandidateRef & func : funcFinder ) { 1022 1025 try { … … 1093 1096 Cost cvtCost = computeApplicationConversionCost( withFunc, symtab ); 1094 1097 1098 if (funcName == "?|?") { 1095 1099 PRINT( 1096 1100 auto appExpr = withFunc->expr.strict_as< ast::ApplicationExpr >(); … … 1108 1112 std::cerr << "cost of conversion is:" << cvtCost << std::endl; 1109 1113 ) 1110 1114 } 1111 1115 if ( cvtCost != Cost::infinity ) { 1112 1116 withFunc->cvtCost = cvtCost; … … 1774 1778 matches.clear(); 1775 1779 } 1776 // ambiguous case, still output candidates to print in error message 1777 if ( cand->cost == minExprCost && thisCost == minCastCost ) { 1778 auto commonAsEnumAttr = common.as<ast::EnumAttrType>(); 1779 if ( commonAsEnumAttr && commonAsEnumAttr->attr == ast::EnumAttribute::Value ) { 1780 auto callExpr = new ast::UntypedExpr( 1781 cand->expr->location, new ast::NameExpr( cand->expr->location, "valueE"), {cand->expr} ); 1782 CandidateFinder finder( context, env ); 1783 finder.find( callExpr ); 1784 CandidateList winners = findMinCost( finder.candidates ); 1785 if (winners.size() != 1) { 1786 SemanticError( callExpr, "Ambiguous expression in valueE..." ); 1787 } 1788 CandidateRef & choice = winners.front(); 1789 // assert( valueCall->result ); 1790 CandidateRef newCand = std::make_shared<Candidate>( 1791 new ast::InitExpr{ 1792 initExpr->location, 1793 // restructureCast( cand->expr, toType ), 1794 choice->expr, 1795 initAlt.designation }, 1796 std::move(env), std::move( open ), std::move( need ), cand->cost + thisCost ); 1797 inferParameters( newCand, matches ); 1798 } else { 1799 CandidateRef newCand = std::make_shared<Candidate>( 1800 new ast::InitExpr{ 1801 initExpr->location, 1802 restructureCast( cand->expr, toType ), 1803 initAlt.designation }, 1804 std::move(env), std::move( open ), std::move( need ), cand->cost + thisCost ); 1805 // currently assertions are always resolved immediately so this should have no effect. 1806 // if this somehow changes in the future (e.g. delayed by indeterminate return type) 1807 // we may need to revisit the logic. 1808 inferParameters( newCand, matches ); 1809 } 1810 } 1780 CandidateRef newCand = std::make_shared<Candidate>( 1781 new ast::InitExpr{ 1782 initExpr->location, 1783 restructureCast( cand->expr, toType ), 1784 initAlt.designation }, 1785 std::move(env), std::move( open ), std::move( need ), cand->cost + thisCost ); 1786 // currently assertions are always resolved immediately so this should have no effect. 1787 // if this somehow changes in the future (e.g. delayed by indeterminate return type) 1788 // we may need to revisit the logic. 1789 inferParameters( newCand, matches ); 1811 1790 } 1812 1791 }
Note: See TracChangeset
for help on using the changeset viewer.