Changeset ea83e00a


Ignore:
Timestamp:
Dec 13, 2016, 5:01:51 PM (5 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
722617d
Parents:
7933351
Message:

attempt to narrow resolution of function calls based on return type if a cast is applied

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    r7933351 rea83e00a  
    608608                makeUnifiableVars( funcType, openVars, resultNeed );
    609609                AltList instantiatedActuals; // filled by instantiate function
     610                if ( targetType && ! targetType->isVoid() ) {
     611                        // attempt to narrow based on expected target type
     612                        Type * returnType = funcType->get_returnVals().front()->get_type();
     613                        if ( ! unify( returnType, targetType, resultEnv, resultNeed, resultHave, openVars, indexer ) ) {
     614                                // unification failed, don't pursue this alternative
     615                                return;
     616                        }
     617                }
     618
    610619                if ( instantiateFunction( funcType->get_parameters(), actualAlt, funcType->get_isVarArgs(), openVars, resultEnv, resultNeed, resultHave, instantiatedActuals ) ) {
    611620                        ApplicationExpr *appExpr = new ApplicationExpr( func.expr->clone() );
     
    740749
    741750                findMinCost( candidates.begin(), candidates.end(), std::back_inserter( alternatives ) );
     751
     752                if ( alternatives.empty() && targetType && ! targetType->isVoid() ) {
     753                        // xxx - this is a temporary hack. If resolution is unsuccessful with a target type, try again without a
     754                        // target type, since it will sometimes succeed when it wouldn't easily with target type binding. For example,
     755                        //   forall( otype T ) lvalue T ?[?]( T *, ptrdiff_t );
     756                        //   const char * x = "hello world";
     757                        //   unsigned char ch = x[0];
     758                        // Fails with simple return type binding. First, T is bound to unsigned char, then (x: const char *) is unified
     759                        // with unsigned char *, which fails because pointer base types must be unified exactly. The new resolver should
     760                        // fix this issue in a more robust way.
     761                        targetType = nullptr;
     762                        visit( untypedExpr );
     763                }
    742764        }
    743765
Note: See TracChangeset for help on using the changeset viewer.