Ignore:
Timestamp:
Jun 29, 2024, 5:02:06 AM (3 weeks ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
4117761
Parents:
7552fde
Message:

Fix the bug that C style enum cannot to use as an lvalue

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/CastCost.cpp

    r7552fde r5ccc733  
    5454                        cost = conversionCost( enumInst, dst, srcIsLvalue, symtab, env );
    5555
    56                         if (Cost::unsafe < cost) {
     56                        if ( !enumInst->base->isCfa ) {
    5757                                static ast::ptr<ast::BasicType> integer = { new ast::BasicType( ast::BasicKind::SignedInt ) };
    5858                                Cost intCost = costCalc( integer, dst, srcIsLvalue, symtab, env );
    5959                                cost = intCost < cost? intCost: cost;
    60                         }
    61                         if ( enumInst->base->isTyped && enumInst->base->base ) {
     60                        } else if ( enumInst->base->isTyped() ) {
    6261                                auto baseConversionCost =
    6362                                        castCost( enumInst->base->base, dst, srcIsLvalue, symtab, env );
     
    7473                                cost = conversionCost( basicType, dst, srcIsLvalue, symtab, env );
    7574                                if ( Cost::unsafe < cost ) {
    76                                         if (auto enumInst = dynamic_cast<const ast::EnumInstType *>(dst)) {
    77                                                 // Always explict cast only for typed enum
    78                                                 if (enumInst->base->isTyped) cost = Cost::unsafe;
     75                                        if ( dynamic_cast<const ast::EnumInstType *>(dst)) {
     76                                                cost = Cost::unsafe;
    7977                                        }
    8078                                }
     
    8583                        cost = conversionCost( zero, dst, srcIsLvalue, symtab, env );
    8684                        if ( Cost::unsafe < cost ) {
    87                                 if (auto enumInst = dynamic_cast<const ast::EnumInstType *>(dst)) {
    88                                         if (enumInst->base->isTyped) cost = Cost::unsafe;
     85                                if ( dynamic_cast<const ast::EnumInstType *>(dst)) {
     86                                        cost = Cost::unsafe;
    8987                                }
    9088                        }
     
    9492                        cost = conversionCost( one, dst, srcIsLvalue, symtab, env );
    9593                        if ( Cost::unsafe < cost ) {
    96                                 if (auto enumInst = dynamic_cast<const ast::EnumInstType *>(dst)) {
    97                                         if (enumInst->base->isTyped) cost = Cost::unsafe;
     94                                if ( dynamic_cast<const ast::EnumInstType *>(dst)) {
     95                                        cost = Cost::unsafe;
    9896                                }
    9997                        }
Note: See TracChangeset for help on using the changeset viewer.