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

Invalid null coalescing operator suggestion for a class consent on a nullable object variable #1918

Open
stephenreay opened this issue Nov 13, 2023 · 1 comment

Comments

@stephenreay
Copy link

Subject Details
Plugin Php Inspections (EA Extended) v5.0.0.0
Language level 7.3

Current behaviour

With a parameter typed as ?SomeClass, class-constant lookups wrapped in an if are suggested to be replaced by null coalescing operator. e.g.:

	function foo(?Something $var = null): void {
		$fragment = null;
		if ($var) {
			$fragment = $var::PREFIX;
		}
		...
	}

The suggested replacement is $var::PREFIX ?? null, but this produces a php error

Expected behaviour

Don't suggest this replacement when the left side of the coalescing operator would be a class constant.

Environment details

IntelliJ IDEA 2023.3 Beta (Ultimate Edition)
Build #IU-233.11799.6, built on November 9, 2023
Licensed to IntelliJ IDEA EAP user: Stephen Reay
Expiration date: December 9, 2023
Runtime version: 17.0.9+7-b1087.3 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 14.1.1
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 24
Metal Rendering is ON
Registry:
debugger.new.tool.window.layout=true
ide.experimental.ui=true
Non-Bundled Plugins:
com.jetbrains.plugins.ini4idea (233.11799.7)
rocks.blackcat.vcl (0.7.2)
net.sjrx.intellij.plugins.systemdunitfiles (223.230322.126)
com.sburlyaev.terminal.plugin (0.6.0)
com.intellij.plugin.applescript (0.121)
org.jetbrains.plugins.ruby (233.11799.6)
com.jetbrains.TabFormat (0.6)
org.intellij.plugins.hcl (233.11799.7)
com.intellij.apacheConfig (233.11799.7)
name.kropp.intellij.makefile (233.11799.7)
com.jetbrains.space (233.11799.10)
org.jetbrains.plugins.vagrant (233.11799.6)
com.jetbrains.php (233.11799.6)
org.jetbrains.plugins.phpstorm-remote-interpreter (233.11799.6)
com.kalessil.phpStorm.phpInspectionsEA (5.0.0.0)
de.espend.idea.php.annotation (9.4.0)
com.intellij.php.psalm (233.11799.6)
com.intellij.php.tools.quality.phpstan (233.11799.6)
com.dwilden.crondescriptor (1.5)
pro.bashsupport (3.3.4.233)
org.asciidoctor.intellij.asciidoc (0.41.0)
mobi.hsz.idea.gitignore (4.5.2)
Pythonid (233.11799.6)
ru.adelf.idea.dotenv (2023.3)
Kotlin: 233-1.9.0-release-358-IJ11799.6

@FlyingDR
Copy link

Another case of what seems to be the same issue:

function test(?object $obj = null): string
{
    return $obj ? $obj::class : '-';
}

Reproducible in EA Ultimate 2023.1

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