Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match support in latte #267

Closed
helvete opened this issue May 3, 2021 · 0 comments
Closed

Match support in latte #267

helvete opened this issue May 3, 2021 · 0 comments

Comments

@helvete
Copy link

helvete commented May 3, 2021

Version: 2.10.3

Latte engine seems to incorrectly handle (inlined) PHP8's match expression. It converts default fallback-branch keyword into 'default' which catches a string 'default' only.

Steps To Reproduce

Any match expression that contains default keyword. Please note, the other branches are not impacted by this by definition - so to reproduce this behaviour, the default branch has to match.

Something like the following snippet should trigger the error.:

{var $var = match(7) {8 => true, default => false,};}

Expected Behaviour

default fallback branch works.. It's even worse for match than for switch, since the match actually has to match :-)

Actual Behaviour

The process ends with UnhandledMatchError and message: Unhandled match value of type int. Demo.

Debugging

To verify what happened I tried to render this template snippet:

<html>                                                                          
{var $promoCodeSize = match(strlen('1234567')){13,14,15,16 => 24, 8,9,10,11,12 => 32, default => 48,};}
<head>  

Then dumped the $code var before the call to eval in Latte\Engine.

The rendered template result:

<?php                                                                           
                                                                                
use Latte\Runtime as LR;                                                        
                                                                                
/** source: /htdocs/src/Bonus/Voucher/../Templates/voucher.latte */          
final class Template8ba8aeabd9 extends Latte\Runtime\Template                   
{                                                                               
                                                                                
    public function main(): array                                               
    {                                                                           
        extract($this->params);                                                 
        echo '<html>                                                            
';                                                                              
        $promoCodeSize = match(strlen('1234567')){13,14,15,16 => 24, 8,9,10,11,12 => 32, 'default' => 48,};
        /* line 2 */;                                                           
        echo '<head>           
        ...                

Please do not hesitate to request any additional debug info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants