Ignore:
Timestamp:
Nov 28, 2019, 4:31:05 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
7030dab
Parents:
9802f4c
Message:

First attempt at better errors on 'No reasonable alternatives' split not found and found but didn't match

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    r9802f4c r71d6bd8  
    601601                ast::ptr< ast::Type > & targetType;
    602602
     603                enum Errors {
     604                        NotFound,
     605                        NoMatch,
     606                        ArgsToFew,
     607                        ArgsToMany,
     608                        RetsToFew,
     609                        RetsToMany,
     610                        NoReason
     611                };
     612
     613                struct {
     614                        Errors code = NotFound;
     615                } reason;
     616
    603617                Finder( CandidateFinder & f )
    604618                : symtab( f.localSyms ), selfFinder( f ), candidates( f.candidates ), tenv( f.env ),
     
    611625                void addCandidate( Args &&... args ) {
    612626                        candidates.emplace_back( new Candidate{ std::forward<Args>( args )... } );
     627                        reason.code = NoReason;
    613628                }
    614629
     
    836851                        // short-circuit if no candidates
    837852                        if ( funcFinder.candidates.empty() ) return;
     853
     854                        reason.code = NoMatch;
    838855
    839856                        std::vector< CandidateFinder > argCandidates =
     
    9891006                        CandidateFinder finder{ symtab, tenv };
    9901007                        finder.find( addressExpr->arg );
     1008
     1009                        if( finder.candidates.empty() ) return;
     1010
     1011                        reason.code = NoMatch;
     1012
    9911013                        for ( CandidateRef & r : finder.candidates ) {
    9921014                                if ( ! isLvalue( r->expr ) ) continue;
     
    10081030                        CandidateFinder finder{ symtab, tenv, toType };
    10091031                        finder.find( castExpr->arg, ResolvMode::withAdjustment() );
     1032
     1033                        if( !finder.candidates.empty() ) reason.code = NoMatch;
    10101034
    10111035                        CandidateList matches;
     
    10931117                        std::vector< ast::SymbolTable::IdData > declList = symtab.lookupId( nameExpr->name );
    10941118                        PRINT( std::cerr << "nameExpr is " << nameExpr->name << std::endl; )
     1119                        if( declList.empty() ) return;
     1120
     1121                        reason.code = NoMatch;
     1122
    10951123                        for ( auto & data : declList ) {
    10961124                                Cost cost = Cost::zero;
     
    12081236                        if ( finder2.candidates.empty() ) return;
    12091237
     1238                        reason.code = NoMatch;
     1239
    12101240                        for ( const CandidateRef & r1 : finder1.candidates ) {
    12111241                                for ( const CandidateRef & r2 : finder2.candidates ) {
     
    12411271                        finder3.find( conditionalExpr->arg3, ResolvMode::withAdjustment() );
    12421272                        if ( finder3.candidates.empty() ) return;
     1273
     1274                        reason.code = NoMatch;
    12431275
    12441276                        for ( const CandidateRef & r1 : finder1.candidates ) {
     
    13191351                        if ( finder2.candidates.empty() ) return;
    13201352
     1353                        reason.code = NoMatch;
     1354
    13211355                        for ( const CandidateRef & r1 : finder1.candidates ) {
    13221356                                for ( const CandidateRef & r2 : finder2.candidates ) {
     
    14191453                                finder.find( initExpr->expr, ResolvMode::withAdjustment() );
    14201454                                for ( CandidateRef & cand : finder.candidates ) {
     1455                                        if(reason.code == NotFound) reason.code = NoMatch;
     1456
    14211457                                        ast::TypeEnvironment env{ cand->env };
    14221458                                        ast::AssertionSet need( cand->need.begin(), cand->need.end() ), have;
     
    15521588
    15531589        if ( mode.failFast && candidates.empty() ) {
    1554                 SemanticError( expr, "No reasonable alternatives for expression " );
     1590                switch(finder.pass.reason.code) {
     1591                case Finder::NotFound:
     1592                        { SemanticError( expr, "No alternatives for expression " ); break; }
     1593                case Finder::NoMatch:
     1594                        { SemanticError( expr, "Invalid application of existing declaration(s) in expression " ); break; }
     1595                case Finder::ArgsToFew:
     1596                case Finder::ArgsToMany:
     1597                case Finder::RetsToFew:
     1598                case Finder::RetsToMany:
     1599                case Finder::NoReason:
     1600                default:
     1601                        { SemanticError( expr->location, "No reasonable alternatives for expression : reasons unkown" ); }
     1602                }
    15551603        }
    15561604
Note: See TracChangeset for help on using the changeset viewer.