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

Grouped rule fails to parse #1241

Open
vkaverin opened this issue Jan 21, 2025 · 1 comment
Open

Grouped rule fails to parse #1241

vkaverin opened this issue Jan 21, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@vkaverin
Copy link

PHP Version: 7.4.28

OS: Linux

The minimal code in which the bug appears:

function arrays() {
  /**
   * @warning can be replaced with isset($array[$key]) or array_key_exists($key, $array)
   */
  array_has_key: {
    in_array($key, array_keys($array));
    in_array($key, array_keys($array), true);
    in_array($key, array_keys_as_ints($array));
    in_array($key, array_keys_as_ints($array), true);
    in_array($key, array_keys_as_strings($array));
    in_array($key, array_keys_as_strings($array), true);
  }
}

Actual Behavior:

15:25:57 Panic while parsing codestyle/rules/optimizations.php: unhandled node: x=*ir.LabelStmt y=*ir.LabelStmt (please, fill an issue on GitHub)


Stack trace: goroutine 600 [running]:
runtime/debug.Stack(0xc00efe05e8, 0xb47160, 0xc082f14580)
	/usr/local/go/src/runtime/debug/stack.go:24 +0x9f
github.com/VKCOM/noverify/src/linter.(*Worker).ParseContents.func1(0xc00dd7d9e0, 0x21, 0xc0628e6000, 0xcdc, 0xcdd, 0x0, 0x0, 0x0, 0xc00efe1d30)
	/go/pkg/mod/github.com/!v!k!c!o!m/noverify@v0.5.4-0.20241227001011-b6eca7b21d0e/src/linter/worker.go:95 +0x76
panic(0xb47160, 0xc082f14580)
	/usr/local/go/src/runtime/panic.go:965 +0x1b9
github.com/VKCOM/noverify/src/phpgrep.(*matcher).eqNode(0xc000622630, 0xc00efe0b10, 0xd49bf8, 0xc0044ffa10, 0xd49bf8, 0xc092557308, 0xc14599)
	/go/pkg/mod/github.com/!v!k!c!o!m/noverify@v0.5.4-0.20241227001011-b6eca7b21d0e/src/phpgrep/matcher.go:785 +0x7c0e
github.com/VKCOM/noverify/src/phpgrep.(*matcher).match(0xc000622630, 0xc00efe0b10, 0xd49bf8, 0xc092557308, 0x0, 0x0, 0x0, 0x0, 0x0, 0xe)
	/go/pkg/mod/github.com/!v!k!c!o!m/noverify@v0.5.4-0.20241227001011-b6eca7b21d0e/src/phpgrep/matcher.go:36 +0x7f
github.com/VKCOM/noverify/src/phpgrep.(*Matcher).Match(...)
	/go/pkg/mod/github.com/!v!k!c!o!m/noverify@v0.5.4-0.20241227001011-b6eca7b21d0e/src/phpgrep/phpgrep.go:59
github.com/VKCOM/noverify/src/linter.(*rootWalker).runRule(0xc079778180, 0xd49bf8, 0xc092557308, 0xc082f14010, 0xc09e3b34a0, 0xc092557308)
	/go/pkg/mod/github.com/!v!k!c!o!m/noverify@v0.5.4-0.20241227001011-b6eca7b21d0e/src/linter/root.go:1811 +0xc7
github.com/VKCOM/noverify/src/linter.(*rootWalker).runRules(0xc079778180, 0xd49bf8, 0xc092557308, 0xc082f14010, 0xc09e3b34a0, 0x1, 0x1)
	/go/pkg/mod/github.com/!v!k!c!o!m/noverify@v0.5.4-0.20241227001011-b6eca7b21d0e/src/linter/root.go:1755 +0x7a
github.com/VKCOM/noverify/src/linter.(*blockWalker).EnterNode(0xc09e3b3ce0, 0xd49bf8, 0xc092557308, 0xc0752c0000)
	/go/pkg/mod/github.com/!v!k!c!o!m/noverify@v0.5.4-0.20241227001011-b6eca7b21d0e/src/linter/block.go:500 +0x346
github.com/VKCOM/noverify/src/ir.(*LabelStmt).Walk(0xc092557308, 0xd4a7b0, 0xc09e3b3ce0)
	/go/pkg/mod/github.com/!v!k!c!o!m/noverify@v0.5.4-0.20241227001011-b6eca7b21d0e/src/ir/walk.go:1097 +0x4b
github.com/VKCOM/noverify/src/linter.(*rootWalker).handleFuncStmts(0xc079778180, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc04daecff0, 0xf, 0xf, ...)
	/go/pkg/mod/github.com/!v!k!c!o!m/noverify@v0.5.4-0.20241227001011-b6eca7b21d0e/src/linter/root.go:457 +0x498
github.com/VKCOM/noverify/src/linter.(*rootChecker).CheckFunction(0xc08c11c0c0, 0xc04daecf00, 0x0)
	/go/pkg/mod/github.com/!v!k!c!o!m/noverify@v0.5.4-0.20241227001011-b6eca7b21d0e/src/linter/root_checker.go:88 +0x5b3
github.com/VKCOM/noverify/src/linter.(*rootWalker).EnterNode(0xc079778180, 0xd49950, 0xc04daecf00, 0xd4a670)
	/go/pkg/mod/github.com/!v!k!c!o!m/noverify@v0.5.4-0.20241227001011-b6eca7b21d0e/src/linter/root.go:236 +0x1046
github.com/VKCOM/noverify/src/ir.(*FunctionStmt).Walk(0xc04daecf00, 0xd4a7d8, 0xc079778180)
	/go/pkg/mod/github.com/!v!k!c!o!m/noverify@v0.5.4-0.20241227001011-b6eca7b21d0e/src/ir/walk.go:888 +0x4b
github.com/VKCOM/noverify/src/ir.(*Root).Walk(0xc054928180, 0xd4a7d8, 0xc079778180)
	/go/pkg/mod/github.com/!v!k!c!o!m/noverify@v0.5.4-0.20241227001011-b6eca7b21d0e/src/ir/walk.go:1533 +0xac
github.com/VKCOM/noverify/src/linter.(*Worker).analyzeFile(0xc0bcb43e50, 0xc08c11c000, 0xc054928180, 0xcdc, 0xcdc, 0xc08c11c000)
	/go/pkg/mod/github.com/!v!k!c!o!m/noverify@v0.5.4-0.20241227001011-b6eca7b21d0e/src/linter/worker.go:312 +0x4e5
github.com/VKCOM/noverify/src/linter.(*Worker).ParseContents(0xc0bcb43e50, 0xc00dd7d9e0, 0x21, 0xc0628e6000, 0xcdc, 0xcdd, 0x0, 0x0, 0x0, 0x0, ...)
	/go/pkg/mod/github.com/!v!k!c!o!m/noverify@v0.5.4-0.20241227001011-b6eca7b21d0e/src/linter/worker.go:143 +0x5f8
github.com/VKCOM/noverify/src/linter.(*Worker).doParseFile(0xc0bcb43e50, 0xc00dd7d9e0, 0x21, 0xc0628e6000, 0xcdc, 0xcdd, 0x0, 0x0, 0x0, 0x0, ...)
	/go/pkg/mod/github.com/!v!k!c!o!m/noverify@v0.5.4-0.20241227001011-b6eca7b21d0e/src/linter/worker.go:256 +0x11b
github.com/VKCOM/noverify/src/linter.(*Linter).analyzeFiles.func3(0xc0c0727601, 0xc00013e0f0, 0xc00436e460, 0xc0c0727620, 0xc0c0727680, 0xc07a009cb0, 0x16)
	/go/pkg/mod/github.com/!v!k!c!o!m/noverify@v0.5.4-0.20241227001011-b6eca7b21d0e/src/linter/linter.go:104 +0x21e
created by github.com/VKCOM/noverify/src/linter.(*Linter).analyzeFiles
	/go/pkg/mod/github.com/!v!k!c!o!m/noverify@v0.5.4-0.20241227001011-b6eca7b21d0e/src/linter/linter.go:94 +0x25f
15:25:57 Failed parsing codestyle/rules/optimizations.php: Panic while parsing codestyle/rules/optimizations.php: unhandled node: x=*ir.LabelStmt y=*ir.LabelStmt (please, fill an issue on GitHub)

Expected Behavior:

Nothing bad happens.

Details:

Separated rules without grouping by array_has_key parses with no errors.

@vkaverin vkaverin added the bug Something isn't working label Jan 21, 2025
@vkaverin
Copy link
Author

Probably the root problem is the same as in #1240.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant