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

Template with {form $form throws "Ternary operator condition is always false." #388

Closed
spaze opened this issue Jul 8, 2023 · 3 comments · Fixed by #395
Closed

Template with {form $form throws "Ternary operator condition is always false." #388

spaze opened this issue Jul 8, 2023 · 3 comments · Fixed by #395
Labels

Comments

@spaze
Copy link
Contributor

spaze commented Jul 8, 2023

I have a template with (source)

{form $form class => "aligned wide blocking"}

That template is included in another template with (source):

{include "common/postForm.latte", form: addPost}

But the fact that it's an included template doesn't matter. It also happens when it's a top-level template with {form $formName} and the presenter does $this->template->formName = 'invoice';

The template is compiled to

         /* line 1 */
        $form = $this->global->formsStack[] = \is_object($ʟ_tmp = $form) ? $ʟ_tmp : $this->global->uiControl[$ʟ_tmp];

Analyzing it on level 4 gives:

 ------ ---------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  Line   Compiled   Admin/Presenters/templates/Blog/common/postForm.latte rendered from MichalSpacekCz\Admin\Presenters\BlogPresenter::add included in Admin/Presenters/templates/Blog/add.latte
         line       See compiled template: /tmp/phpstan-latte/app/Admin/Presenters/templates/Blog/common/postForm.latte.5dfda1a7df692b7ec28925763179a399.php
 ------ ---------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  1      53         Ternary operator condition is always false.
 ------ ---------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

I don't know what to do with that :-(

@lulco
Copy link
Contributor

lulco commented Jul 8, 2023

Includes are not covered very well :( personally, I don’t use them much, so we have to look at them closely. Would be very helpful if you could create failing test cases

@spaze
Copy link
Contributor Author

spaze commented Jul 8, 2023

Thanks though it seems the issue is also present when the template is a top-level one and not included. I've updated the description.

@lulco
Copy link
Contributor

lulco commented Jul 8, 2023

I see, this is because of dynamic form name (variable is used here). I will check if we know the value of variable at the point when we are processing forms, because phpstan knows it later.

spaze added a commit to spaze/michalspacek.cz that referenced this issue Jul 14, 2023
This has also allowed me to replace `{form $form}` with `{form date}`, similar work done previous commits. This works around efabrica-team/phpstan-latte#388.
@lulco lulco added the forms label Jul 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants