Changeset 2f31773


Ignore:
Timestamp:
Aug 14, 2024, 1:13:06 PM (3 months ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
master
Children:
8da3cc4d
Parents:
f9ad69d
Message:

Improve inability to declare a struct member having a managed type via typeof.

Fix is evaluating typeof on both types in a cast; one was missing.

One layer of struct wrapping now works, with its test added. Multiple layers of wrapping still does not work.

Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CandidateFinder.cpp

    rf9ad69d r2f31773  
    12411241                Cost minCastCost = Cost::infinity;
    12421242                for ( CandidateRef & cand : finder.candidates ) {
     1243                        ast::ptr< ast::Type > fromType = cand->expr->result;
     1244                        assert( fromType );
     1245                        fromType = resolveTypeof( fromType, context );
     1246                        fromType = adjustExprType( fromType, tenv, symtab );
     1247
    12431248                        ast::AssertionSet need( cand->need.begin(), cand->need.end() ), have;
    12441249                        ast::OpenVarSet open( cand->open );
     
    12501255                        // subexpression results that are cast directly. The candidate is invalid if it
    12511256                        // has fewer results than there are types to cast to.
    1252                         int discardedValues = cand->expr->result->size() - toType->size();
     1257                        int discardedValues = fromType->size() - toType->size();
    12531258                        if ( discardedValues < 0 ) continue;
    12541259
    12551260                        // unification run for side-effects
    1256                         unify( toType, cand->expr->result, cand->env, need, have, open );
     1261                        unify( toType, fromType, cand->env, need, have, open );
    12571262                        Cost thisCost =
    12581263                                (castExpr->isGenerated == ast::GeneratedFlag::GeneratedCast)
    1259                                         ? conversionCost( cand->expr->result, toType, cand->expr->get_lvalue(), symtab, cand->env )
    1260                                         : castCost( cand->expr->result, toType, cand->expr->get_lvalue(), symtab, cand->env );
     1264                                        ? conversionCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env )
     1265                                        : castCost( fromType, toType, cand->expr->get_lvalue(), symtab, cand->env );
    12611266                       
    12621267                        // Redefine enum cast
    1263                         auto argAsEnum = cand->expr->result.as<ast::EnumInstType>();
     1268                        auto argAsEnum = fromType.as<ast::EnumInstType>();
    12641269                        auto toAsEnum = toType.as<ast::EnumInstType>();
    12651270                        if ( argAsEnum && toAsEnum && argAsEnum->name != toAsEnum->name ) {
     
    12721277                        PRINT(
    12731278                                std::cerr << "working on cast with result: " << toType << std::endl;
    1274                                 std::cerr << "and expr type: " << cand->expr->result << std::endl;
     1279                                std::cerr << "and expr type: " << fromType << std::endl;
    12751280                                std::cerr << "env: " << cand->env << std::endl;
    12761281                        )
Note: See TracChangeset for help on using the changeset viewer.