Changeset b96b1c0


Ignore:
Timestamp:
Jun 16, 2023, 3:24:20 PM (11 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
64727bd
Parents:
3a7aa94
Message:

Reproduing changes from commit eb8d791. This fixes most of the errors from resolver update.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    r3a7aa94 rb96b1c0  
    315315        /// Instantiates an argument to match a parameter, returns false if no matching results left
    316316        bool instantiateArgument(
     317                const CodeLocation & location,
    317318                const ast::Type * paramType, const ast::Init * init, const ExplodedArgs_new & args,
    318319                std::vector< ArgPack > & results, std::size_t & genStart, const ast::SymbolTable & symtab,
     
    325326                                // xxx - dropping initializer changes behaviour from previous, but seems correct
    326327                                // ^^^ need to handle the case where a tuple has a default argument
    327                                 if ( ! instantiateArgument(
     328                                if ( ! instantiateArgument( location,
    328329                                        type, nullptr, args, results, genStart, symtab, nTuples ) ) return false;
    329330                                nTuples = 0;
     
    377378                                                        // push empty tuple expression
    378379                                                        newResult.parent = i;
    379                                                         newResult.expr = new ast::TupleExpr{ CodeLocation{}, {} };
     380                                                        newResult.expr = new ast::TupleExpr( location, {} );
    380381                                                        argType = newResult.expr->result;
    381382                                                } else {
     
    692693                /// Builds a list of candidates for a function, storing them in out
    693694                void makeFunctionCandidates(
     695                        const CodeLocation & location,
    694696                        const CandidateRef & func, const ast::FunctionType * funcType,
    695697                        const ExplodedArgs_new & args, CandidateList & out
     
    738740                                        for (size_t i=0; i<nParams; ++i) {
    739741                                                auto obj = funcDecl->params[i].strict_as<ast::ObjectDecl>();
    740                                                 if (!instantiateArgument(
     742                                                if ( !instantiateArgument( location,
    741743                                                        funcType->params[i], obj->init, args, results, genStart, symtab)) return;
    742744                                        }
     
    748750                                // matches
    749751                                // no default args for indirect calls
    750                                 if ( ! instantiateArgument(
     752                                if ( !instantiateArgument( location,
    751753                                        param, nullptr, args, results, genStart, symtab ) ) return;
    752754                        }
     
    978980                                                        newFunc->expr =
    979981                                                                referenceToRvalueConversion( newFunc->expr, newFunc->cost );
    980                                                         makeFunctionCandidates( newFunc, function, argExpansions, found );
     982                                                        makeFunctionCandidates( untypedExpr->location,
     983                                                                newFunc, function, argExpansions, found );
    981984                                                }
    982985                                        } else if (
     
    985988                                                if ( const ast::EqvClass * clz = func->env.lookup( *inst ) ) {
    986989                                                        if ( auto function = clz->bound.as< ast::FunctionType >() ) {
    987                                                                 CandidateRef newFunc{ new Candidate{ *func } };
     990                                                                CandidateRef newFunc( new Candidate( *func ) );
    988991                                                                newFunc->expr =
    989992                                                                        referenceToRvalueConversion( newFunc->expr, newFunc->cost );
    990                                                                 makeFunctionCandidates( newFunc, function, argExpansions, found );
     993                                                                makeFunctionCandidates( untypedExpr->location,
     994                                                                        newFunc, function, argExpansions, found );
    991995                                                        }
    992996                                                }
     
    10141018                                                                newOp->expr =
    10151019                                                                        referenceToRvalueConversion( newOp->expr, newOp->cost );
    1016                                                                 makeFunctionCandidates( newOp, function, argExpansions, found );
     1020                                                                makeFunctionCandidates( untypedExpr->location,
     1021                                                                        newOp, function, argExpansions, found );
    10171022                                                        }
    10181023                                                }
     
    11791184                                        thisCost.incSafe( discardedValues );
    11801185                                        // select first on argument cost, then conversion cost
    1181                                         if (cand->cost < minExprCost || cand->cost == minExprCost && thisCost < minCastCost) {
     1186                                        if ( cand->cost < minExprCost || ( cand->cost == minExprCost && thisCost < minCastCost ) ) {
    11821187                                                minExprCost = cand->cost;
    11831188                                                minCastCost = thisCost;
     
    11871192                                        }
    11881193                                        // ambiguous case, still output candidates to print in error message
    1189                                         if (cand->cost == minExprCost && thisCost == minCastCost) {
     1194                                        if ( cand->cost == minExprCost && thisCost == minCastCost ) {
    11901195                                                CandidateRef newCand = std::make_shared<Candidate>(
    11911196                                                        restructureCast( cand->expr, toType, castExpr->isGenerated ),
     
    17001705                                                // count one safe conversion for each value that is thrown away
    17011706                                                thisCost.incSafe( discardedValues );
    1702                                                 if (cand->cost < minExprCost || cand->cost == minExprCost && thisCost < minCastCost) {
     1707                                                if ( cand->cost < minExprCost || ( cand->cost == minExprCost && thisCost < minCastCost ) ) {
    17031708                                                        minExprCost = cand->cost;
    17041709                                                        minCastCost = thisCost;
     
    17061711                                                }
    17071712                                                // ambiguous case, still output candidates to print in error message
    1708                                                 if (cand->cost == minExprCost && thisCost == minCastCost) {
     1713                                                if ( cand->cost == minExprCost && thisCost == minCastCost ) {
    17091714                                                        CandidateRef newCand = std::make_shared<Candidate>(
    17101715                                                        new ast::InitExpr{
Note: See TracChangeset for help on using the changeset viewer.