Changeset cdb4eaa for src/ResolvExpr


Ignore:
Timestamp:
Apr 17, 2024, 2:27:56 PM (2 months ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
748c751
Parents:
76c7addb
Message:

Fix succ(Enum) error and resolution ambiguity of enum with inheritance

Location:
src/ResolvExpr
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    r76c7addb rcdb4eaa  
    513513                                        // add new result
    514514                                        assert( common );
    515                                         // auto attrType = common.as<ast::EnumAttrType>();
    516                                         // if ( attrType && ( attrType->attr == ast::EnumAttribute::Value ) ) {
    517                                         //      auto callExpr = new ast::UntypedExpr(
    518                                         //              expr->location, new ast::NameExpr( expr->location, "valueE"), {expr} );
    519                                         //      CandidateFinder finder( context, env );
    520                                         //      finder.find( callExpr );
    521                                         //      CandidateList winners = findMinCost( finder.candidates );
    522                                         //      if (winners.size() != 1) {
    523                                         //              SemanticError( callExpr, "Ambiguous expression in valueE" );
    524                                         //      }
    525                                         //      CandidateRef & choice = winners.front();
    526                                         //      choice->expr = referenceToRvalueConversion( choice->expr, choice->cost );
    527 
    528                                         //      results.emplace_back(
    529                                         //              i, choice->expr,
    530                                         //              std::move( env ), std::move( need ), std::move( have ), std::move( open ),
    531                                         //              nextArg + 1, nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j );
    532                                         // } else {
    533515                                                results.emplace_back(
    534516                                                        i, expr, std::move( env ), std::move( need ), std::move( have ), std::move( open ),
     
    921903                                CandidateList winners = findMinCost( finder.candidates );
    922904                                if (winners.size() != 1) {
    923                                         SemanticError( callExpr, "Ambiguous expression in valueE" );
     905                                        SemanticError( callExpr, "Ambiguous expression in valueE..." );
    924906                                }
    925907                                CandidateRef & choice = winners.front();
    926                                 // choice->cost.incSafe();
     908                                choice->cost.incVar();
    927909                                candidates.emplace_back( std::move(choice) );
    928910                        }
     
    18011783                                                        CandidateList winners = findMinCost( finder.candidates );
    18021784                                                        if (winners.size() != 1) {
    1803                                                                 SemanticError( callExpr, "Ambiguous expression in valueE" );
     1785                                                                SemanticError( callExpr, "Ambiguous expression in valueE..." );
    18041786                                                        }
    18051787                                                        CandidateRef & choice = winners.front();
     
    21612143                CandidateList winners = findMinCost( finder.candidates );
    21622144                if (winners.size() != 1) {
    2163                         SemanticError( callExpr, "Ambiguous expression in valueE" );
     2145                        SemanticError( callExpr, "Ambiguous expression in valueE..." );
    21642146                }
    21652147                CandidateRef & choice = winners.front();
  • src/ResolvExpr/ConversionCost.cc

    r76c7addb rcdb4eaa  
    362362
    363363void ConversionCost::postvisit( const ast::EnumInstType * inst ) {
    364         if ( inst->base && inst->base->base ) {
    365                 if ( auto dstAsAttr = dynamic_cast<const ast::EnumAttrType *>( dst ) ) {
    366                         auto instAsAttr = ast::EnumAttrType( inst, dstAsAttr->attr );
    367                         if ( instAsAttr.match(dstAsAttr) ) {
    368                                 cost.incUnsafe();
    369                         }
    370 
    371                 } else if ( auto dstAsInst = dynamic_cast<const ast::EnumInstType *>( dst ) ) {
    372                         if (inst->base && dstAsInst->base) {
    373                                 if (inst->base == dstAsInst->base) {
    374                                         cost.incUnsafe();
    375                                 }
    376                         }
    377                 } else {
    378                         auto instAsVal = ast::EnumAttrType( inst, ast::EnumAttribute::Value );
    379                         cost = costCalc( &instAsVal, dst, srcIsLvalue, symtab, env );
    380                         if ( cost < Cost::infinity ) {
    381                                 cost.incUnsafe();
    382                         }
    383                 }
    384                 return;
     364        if ( auto dstAsInst = dynamic_cast<const ast::EnumInstType *>( dst ) ) {
     365                if (inst->base && dstAsInst->base) {
     366                        if (inst->base->name == dstAsInst->base->name) {
     367                                cost = Cost::zero;
     368                                return;
     369                        }
     370                }
    385371        }
    386372        static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicType::SignedInt ) };
Note: See TracChangeset for help on using the changeset viewer.