diff --git a/alib2algo/src/regexp/simplify/RegExpOptimizeFormalPart.cxx b/alib2algo/src/regexp/simplify/RegExpOptimizeFormalPart.cxx index 015a7740aec9bc625053f7e112dc97105fff7f27..932e4cf8d2f4e0bf4f20dcbf2a0effb59c6f69f7 100644 --- a/alib2algo/src/regexp/simplify/RegExpOptimizeFormalPart.cxx +++ b/alib2algo/src/regexp/simplify/RegExpOptimizeFormalPart.cxx @@ -470,16 +470,19 @@ bool RegExpOptimize::V3( FormalRegExpElement * & n ) const */ bool RegExpOptimize::V4( FormalRegExpElement * & n ) const { - FormalRegExpConcatenation * node = dynamic_cast<FormalRegExpConcatenation *>( n ); + FormalRegExpIteration * node = dynamic_cast<FormalRegExpIteration *>( n ); if( ! node ) return false; - FormalRegExpIteration * leftIte = dynamic_cast<FormalRegExpIteration *>( node->left ); + FormalRegExpConcatenation * child = dynamic_cast<FormalRegExpConcatenation *>( node->element ); + if( ! child ) return false; + + FormalRegExpIteration * leftIte = dynamic_cast<FormalRegExpIteration *>( child->left ); if( ! leftIte ) return false; - FormalRegExpIteration * rightIte = dynamic_cast<FormalRegExpIteration *>( node->right ); + FormalRegExpIteration * rightIte = dynamic_cast<FormalRegExpIteration *>( child->right ); if( ! rightIte ) return false; - n = new FormalRegExpAlternation(std::move( *leftIte->element ), std::move(*rightIte->element)); + n = new FormalRegExpIteration(FormalRegExpAlternation(std::move( *leftIte->element ), std::move(*rightIte->element))); delete node; return true;