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

Variable usage detection broken for code inside {foreach} in {block} #159

Open
nufue opened this issue Mar 13, 2024 · 3 comments
Open

Variable usage detection broken for code inside {foreach} in {block} #159

nufue opened this issue Mar 13, 2024 · 3 comments
Labels

Comments

@nufue
Copy link

nufue commented Mar 13, 2024

Describe the bug
The detection of usage of variables created via {var} seems to be broken when usage occurs inside {foreach} while the whole template is enclosed in {block}..{/block}.

Environment (please complete the following information):

  • PhpStorm version 2023.3.5
  • Plugin version 2.0.0@beta1
  • PHPStorm cache invalidated and cleaned

To Reproduce

  1. Paste code below to a new file.
  2. See that $level in {var $level = 0} is hinted as unused variable, which is not true, as it is used inside of {foreach}. Also $level in {php $level++} is marked as Undefined variable.

Code

{block content}
	{var $level = 0}
	{foreach $groups as $value}
		{php $level++}
	{/foreach}
{/block}

Screenshots
image

Additional context
If I remove {block content} and {/block} from the code, the variable is no longer marked as unused.

@SendiMyrkr
Copy link

Same problem is for {if} inside {define}
unused-undefined-variables

@mesour mesour added the v2.0 label Apr 25, 2024
@Marian-Kechlibar
Copy link

Same with printing.

An element of an array is indicated as "Print invalid type: array" in Inspection, as if I were trying to print the entire array.

A variable that is declared as default null is indicated as "Print invalid type: null", even though the printout occurs in n:ifset="" condition that rules out the value of null.

@Marian-Kechlibar
Copy link

Also, the inspection for print invalid type is named "Tag var content". There are two such entries in Inspections / Latte / Not allowed, one of them actually checks tag var content, the other checks invalid printing types.

This is obviously a minor misprint, copied value from an older inspection, still a bit confusing if you want to turn the broken printing detections off.

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

No branches or pull requests

4 participants