Add downgrade-nullable-argument-mismatch config option for nullability-only argument type mismatches - #426
Merged
AJenbo merged 5 commits intoSep 6, 2026
Conversation
…gle, off by default
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
and config reference
AJenbo
force-pushed
the
feat/downgrade-nullable-argument-mismatch
branch
from
September 6, 2026 23:24
d89567d to
eb5fe65
Compare
Contributor
|
Thanks, I had actually considered disabeling this diagnostic by default as many developers probably ignore it IRL |
Contributor
Author
|
@AJenbo you'r most welcome :D and I agree with u about it. i guess now it makes more sense with this toggle.. letting strict teams keep the guard-rail while others can lower it to warnings without disabling it entirely. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #411: When a value with type
null|stringreaches a function parameter expectingstringthrough a negated guard clause likeif ($password !== null && ! is_string($password)), the type narrowing correctly computes tonull|string(every non-null member is alreadystring, so the negation leavesnullreachable). The resulting diagnostic is mathematically correct -nullcan still reach the call. However, some projects prefer to treat this as a lower-priority warning rather than an error, since every non-null possibility already satisfies the parameter (only nullability is the gap here).So, I added an opt-in
.phpantom.tomlconfig option[diagnostics] downgrade-nullable-argument-mismatchto downgrade thetype_mismatch_argumentto WARNING severity when the only unsatisfied member of an argument's union type isnull. Off by default, so existing projects see no behavior change until opted in.Changes Made
src/config.rs- AddedDiagnosticsConfig.downgrade_nullable_argument_mismatch: Option<bool>field with accessor method and two unit tests verifying parse and default-to-false behavior.src/diagnostics/type_errors/mod.rs- When building thetype_mismatch_argumentdiagnostic, check if onlynullfails compatibility and the new option is enabled; if so, set severity toDiagnosticSeverity::WARNING. The message and diagnostic code unchanged.tests/integration/diagnostics_type_errors.rs- Three new integration tests: (1) issue # 411 scenario stays ERROR by default, (2) same case downgrades to WARNING when the option is enabled, (3) genuine non-null type mismatches stay as ERROR even when option is enabled.config-schema.json- Addeddowngrade-nullable-argument-mismatchboolean property to the[diagnostics]schema.docs/CHANGELOG.md+docs/configuration.md- Documented the new option for end users.Checklist
CHANGELOG.mddocs/)config-schema.json)how it works, how it's organized), including any code drafted by an LLM.
an eye towards deleting anything that is irrelevant, clarifying anything
that is confusing, and adding details that are relevant & needed.