Changeset d68a3f7 for src


Ignore:
Timestamp:
Jul 19, 2024, 6:06:19 PM (38 hours ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
18d7aaf
Parents:
e6128959
Message:

Update makeEnumOffsetCast to not report error for cast to non-parent type (later be a losing candidate)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    re6128959 rd68a3f7  
    522522                                                                CandidateFinder subFinder( context, env );
    523523                                                                expr = subFinder.makeEnumOffsetCast(argAsEnum, paramAsEnum, expr, c);
    524                                                                 results.emplace_back(
    525                                                                         i, expr, std::move( env ), std::move( need ), std::move( have ), std::move( open ),
    526                                                                         nextArg + 1, nTuples, expl.cost + c, expl.exprs.size() == 1 ? 0 : 1, j );
     524                                                                if ( expr )
     525                                                                        results.emplace_back(
     526                                                                                i, expr, std::move( env ), std::move( need ), std::move( have ), std::move( open ),
     527                                                                                nextArg + 1, nTuples, expl.cost + c, expl.exprs.size() == 1 ? 0 : 1, j );
    527528                                                                continue;
    528529                                                        } else {
     
    12651266                                CandidateFinder subFinder(context, tenv);
    12661267                                ast::ptr<ast::Expr> offsetExpr = subFinder.makeEnumOffsetCast(argAsEnum, toAsEnum, cand->expr, thisCost);
    1267                                 cand->expr = offsetExpr;
     1268                                if ( offsetExpr )
     1269                                        cand->expr = offsetExpr;
    12681270                        }
    12691271
     
    21512153
    21522154const ast::Expr * CandidateFinder::makeEnumOffsetCast( const ast::EnumInstType * src,
    2153         const ast::EnumInstType * dst,
    2154         const ast::Expr * expr,
    2155         Cost minCost ) {
    2156        
     2155        const ast::EnumInstType * dst, const ast::Expr * expr, Cost minCost ) {
    21572156        auto srcDecl = src->base;
    21582157        auto dstDecl = dst->base;
     
    21792178                                CandidateRef & choice = winners.front();
    21802179                                choice->expr = new ast::CastExpr(expr->location, choice->expr, dstChild, ast::GeneratedFlag::ExplicitCast);
    2181                                 castToDst = new ast::CastExpr(
    2182                                         makeEnumOffsetCast( src, dstChild, choice->expr, minCost ),
    2183                                         dst);
     2180                                auto destExpr = makeEnumOffsetCast( src, dstChild, choice->expr, minCost );
     2181                                if ( !destExpr ) continue;
     2182                                castToDst = new ast::CastExpr( destExpr, dst );
    21842183                        } else {
    21852184                                castToDst = new ast::CastExpr( expr, dst );
     
    21882187                }
    21892188        }
    2190         SemanticError(expr, src->base->name + " is not a subtype of " + dst->base->name);
    21912189        return nullptr;
    21922190}
Note: See TracChangeset for help on using the changeset viewer.