Skip to content

Report the witness type of mixed as the given type - #7293

Merged
ondrejmirtes merged 2 commits into
2.3.xfrom
report-mixed-witness-type-as-given
Dec 2, 2026
Merged

ondrejmirtes merged 2 commits into
2.3.xfrom
report-mixed-witness-type-as-given

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

Follow-up to the mixed witness types (checkMixedWitnessTypes, bleeding edge).

When mixed itself is accepted but its witness type is not, the error now names the witness as the given type, without the "Type mixed is … on some paths." tip:

function foo(bool $c, mixed $m): string
{
	return $c ? $m : 1;
}
7 8 9 10
explicit mixed returns int returns int returns mixed returns mixed
implicit mixed returns int returns int returns int returns mixed
  • RuleLevelHelper::accepts() checks the mixed itself first, so a mixed rejected on its own (explicit from level 9, implicit on level 10) is still reported as mixed.
  • RuleLevelHelperAcceptsResult gets an optional ?Type $witnessType, used by the rules that describe the given type: arguments, return, return after finally, property assignment and default value, yield and yield from.
  • The native RuleLevelHelper.cpp mirrors it.
  • New levels topic mixedWitness covers returns, arguments and property assignments for explicit and implicit mixed, including nullable and union witnesses.

When mixed is accepted but its witness type is not, rules now describe the
witness as the given type: `return $c ? $mixed : 1;` in a function returning
string reports "should return string but returns int." from level 7 instead
of "returns mixed" with a tip saying mixed is int on some paths.

RuleLevelHelper::accepts() checks the mixed itself first, so a mixed that
is rejected on its own - explicit mixed from level 9, implicit mixed on
level 10 - is still reported as mixed. RuleLevelHelperAcceptsResult carries
the rejected witness type for the rules describing the given type. The
native extension mirrors it.

Amp-Thread-ID: https://ampcode.com/threads/T-01a237b0-3e9f-77ea-bd9b-d9a06b69686b
@ondrejmirtes ondrejmirtes reopened this Dec 2, 2026
@ondrejmirtes
ondrejmirtes merged commit 91f71e3 into 2.3.x Dec 2, 2026
402 of 424 checks passed
@ondrejmirtes
ondrejmirtes deleted the report-mixed-witness-type-as-given branch December 2, 2026 19:36
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

Successfully merging this pull request may close these issues.

1 participant