Skip to content

Commit 95764e5

Browse files
committed
Merge degraded members into one oversized array only when each is an array
OversizedArrayWidening merged its results into one general array when each member held a shape it degraded. A member such as bool|int|list{...}|string holds shapes without being an array, and its iterable key and value types are *ERROR*, so the merged array was non-empty-array<*ERROR*, *ERROR*>&oversized-array. Such members now stay apart. Amp-Thread-ID: https://ampcode.com/threads/T-01a21c4a-f4aa-73fb-ab5d-2ac321ba792a
1 parent 79cd194 commit 95764e5

3 files changed

Lines changed: 158 additions & 1 deletion

File tree

‎src/Type/Combinator/OversizedArrayWidening.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ public function apply(array $types): array
5757
return self::degrade($type);
5858
});
5959

60-
if (!$isOversized) {
60+
// a value type that only holds shapes, such as `int|array{a: int}`,
61+
// has no keys and values to merge
62+
if (!$isOversized || !$result->isArray()->yes()) {
6163
$eachIsOversized = false;
6264
}
6365

‎tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3699,6 +3699,11 @@ public function testBug13164(): void
36993699
$this->analyse([__DIR__ . '/data/bug-13164.php'], []);
37003700
}
37013701

3702+
public function testBug15861(): void
3703+
{
3704+
$this->analyse([__DIR__ . '/data/bug-15861.php'], []);
3705+
}
3706+
37023707
public function testFloatConstantLoopGeneralize(): void
37033708
{
37043709
$this->analyse([__DIR__ . '/../../Analyser/nsrt/float-constant-loop-generalize.php'], []);
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug15861;
4+
5+
function xl(string $s): string { return $s; }
6+
function text(string $s): string { return $s; }
7+
function f(): void {
8+
$search_options = [
9+
"demos" => [
10+
"title" => xl("Demographics"),
11+
"cols" => [
12+
"patient_name" => ["heading" => xl("Patient Name"), "width" => "10%"],
13+
"patient_id" => ["heading" => xl("PID"), "width" => "nowrap"],
14+
"patient_age" => ["heading" => xl("Age"), "width" => "nowrap"],
15+
"patient_sex" => ["heading" => xl("Gender"), "width" => "nowrap"],
16+
"patient_ethnic" => ["heading" => xl("Ethnicity"), "width" => "10%"],
17+
"patient_race" => ["heading" => xl("Race"), "width" => "10%"],
18+
"users_provider" => ["heading" => xl("Provider"), "width" => "10%"]
19+
],
20+
],
21+
"diagnosis_check" => [
22+
"hidden" => true,
23+
"cols" => [
24+
"other_date" => ["heading" => xl("Diagnosis Date"), "width" => "nowrap"],
25+
"patient_name" => ["heading" => xl("Patient Name"), "width" => "10%"],
26+
"patient_id" => ["heading" => xl("PID"), "width" => "nowrap"],
27+
"patient_age" => ["heading" => xl("Age"), "width" => "nowrap"],
28+
"patient_sex" => ["heading" => xl("Gender"), "width" => "nowrap"],
29+
"patient_ethnic" => ["heading" => xl("Ethnicity"), "width" => "10%"],
30+
"users_provider" => ["heading" => xl("Provider"), "width" => "10%"],
31+
"lists_title" => [ "width" => "15%"], // Heading assigned later
32+
"pr_diagnosis" => ["heading" => xl("Diagnosis Codes"), "width" => "20%"]
33+
],
34+
"sort_cols" => -1,
35+
],
36+
"prescripts" => [
37+
"title" => xl("Prescriptions"),
38+
"cols" => [
39+
"other_date" => ["heading" => xl("Filled"), "width" => "10%"],
40+
"patient_name" => ["heading" => xl("Patient Name"), "width" => "10%"],
41+
"patient_id" => ["heading" => xl("PID"), "width" => "nowrap"],
42+
"patient_age" => ["heading" => xl("Age"), "width" => "nowrap"],
43+
"patient_sex" => ["heading" => xl("Gender"), "width" => "nowrap"],
44+
"rx_drug" => ["heading" => xl("Drug"), "width" => "20%"],
45+
"rx_medicine_units" => ["heading" => xl("Units"), "width" => "nowrap"],
46+
"rx_directions" => ["heading" => xl("Directions"), "width" => "10%"],
47+
"rx_quantity" => ["heading" => xl("Quantity"), "width" => "nowrap"],
48+
"rx_refills" => ["heading" => xl("Refills"), "width" => "nowrap"]
49+
],
50+
],
51+
"comms" => [
52+
"title" => xl("Communication"),
53+
"cols" => [
54+
"patient_date" => ["heading" => xl("Date Created"), "width" => "nowrap"],
55+
"patient_name" => ["heading" => xl("Patient Name"), "width" => "10%"],
56+
"patient_id" => ["heading" => xl("PID"), "width" => "nowrap"],
57+
"patient_age" => ["heading" => xl("Age"), "width" => "nowrap"],
58+
"patient_sex" => ["heading" => xl("Gender"), "width" => "nowrap"],
59+
"patient_ethnic" => ["heading" => xl("Ethnicity"), "width" => "10%"],
60+
"users_provider" => ["heading" => xl("Provider"), "width" => "10%"],
61+
"communications" => ["heading" => xl("Communication"), "width" => "15%"]
62+
],
63+
],
64+
"insurers" => [
65+
"title" => xl("Insurance Companies"),
66+
"cols" => [
67+
"patient_date" => ["heading" => xl("Date Created"), "width" => "nowrap"],
68+
"patient_name" => ["heading" => xl("Patient Name"), "width" => "10%"],
69+
"patient_id" => ["heading" => xl("PID"), "width" => "nowrap"],
70+
"patient_age" => ["heading" => xl("Age"), "width" => "nowrap"],
71+
"patient_sex" => ["heading" => xl("Gender"), "width" => "nowrap"],
72+
"patient_ethnic" => ["heading" => xl("Ethnicity"), "width" => "10%"],
73+
"users_provider" => ["heading" => xl("Insurance Provider"), "width" => "10%"],
74+
"ins_name" => ["heading" => xl("Primary Insurance"), "width" => "10%"]
75+
],
76+
],
77+
"encounts" => [
78+
"title" => xl("Encounters"),
79+
"cols" => [
80+
"other_date" => ["heading" => xl("Encounter Date"), "width" => "nowrap"],
81+
"patient_name" => ["heading" => xl("Patient Name"), "width" => "10%"],
82+
"patient_id" => ["heading" => xl("PID"), "width" => "nowrap"],
83+
"patient_age" => ["heading" => xl("Age"), "width" => "nowrap"],
84+
"patient_sex" => ["heading" => xl("Gender"), "width" => "nowrap"],
85+
"users_provider" => ["heading" => xl("Provider"), "width" => "10%"],
86+
"enc_type" => ["heading" => xl("Encounter type"), "width" => "20%"],
87+
"enc_reason" => ["heading" => xl("Reason"), "width" => "15%"],
88+
"enc_facility" => ["heading" => xl("Facility"), "width" => "10%"],
89+
"enc_discharge" => ["heading" => xl("Discharge Disposition"), "width" => "10%"]
90+
],
91+
],
92+
"observs" => [
93+
"title" => xl("Observations"),
94+
"cols" => [
95+
"other_date" => ["heading" => xl("Date"), "width" => "nowrap"],
96+
"patient_name" => ["heading" => xl("Patient Name"), "width" => "10%"],
97+
"patient_id" => ["heading" => xl("PID"), "width" => "nowrap"],
98+
"patient_age" => ["heading" => xl("Age"), "width" => "nowrap"],
99+
"patient_sex" => ["heading" => xl("Gender"), "width" => "nowrap"],
100+
"users_provider" => ["heading" => xl("Provider"), "width" => "10%"],
101+
"obs_code" => ["heading" => xl("Code"), "width" => "nowrap"],
102+
"obs_description" => ["heading" => xl("Description"), "width" => "15%"],
103+
"obs_type" => ["heading" => xl("Type"), "width" => "10%"],
104+
"obs_value" => ["heading" => xl("Value"), "width" => "nowrap"],
105+
"obs_units" => ["heading" => xl("Units"), "width" => "nowrap"],
106+
"obs_comments" => ["heading" => xl("Comments"), "width" => "20%"]
107+
],
108+
"sort_cols" => -1,
109+
],
110+
"procs" => [
111+
"title" => xl("Procedures"),
112+
"cols" => [
113+
"other_date" => ["heading" => xl("Order Date"), "width" => "nowrap"],
114+
"patient_name" => ["heading" => xl("Patient Name"), "width" => "10%"],
115+
"patient_id" => ["heading" => xl("PID"), "width" => "nowrap"],
116+
"users_provider" => ["heading" => xl("Procedure Provider"), "width" => "10%"],
117+
"pr_lab" => ["heading" => xl("Lab"), "width" => "10%"],
118+
"pr_status" => ["heading" => xl("Status"), "width" => "nowrap"],
119+
"prc_procedure" => ["heading" => xl("Procedure Test"), "width" => "10%"],
120+
"pr_diagnosis" => ["heading" => xl("Primary Diagnosis"), "width" => "20%"],
121+
"prc_diagnoses" => ["heading" => xl("Diagnosis Codes"), "width" => "20%"]
122+
],
123+
"sort_cols" => -2,
124+
"acl" => ["encounters", "coding_a"]
125+
],
126+
"results" => [
127+
"title" => xl("Lab Results"),
128+
"cols" => [
129+
"other_date" => ["heading" => xl("Date"), "width" => "nowrap"],
130+
"result_facility" => ["heading" => xl("Facility"), "width" => "10%"],
131+
"patient_id" => ["heading" => xl("PID"), "width" => "nowrap"],
132+
"result_description" => ["heading" => xl("Procedure Test"), "width" => "10%"],
133+
"result_result" => ["heading" => xl("Result"), "width" => "5%"],
134+
"result_units" => ["heading" => xl("Unit"), "width" => "nowrap"],
135+
"result_range" => ["heading" => xl("Range"), "width" => "5%"],
136+
"result_abnormal" => ["heading" => xl("Abnormal"), "width" => "nowrap"],
137+
"result_comments" => ["heading" => xl("Comments"), "width" => "20%"],
138+
"result_document_id" => ["heading" => xl("Document ID"), "width" => "nowrap"],
139+
],
140+
"sort_cols" => -2,
141+
"acl" => ["patients", "lab"]
142+
]
143+
144+
];
145+
foreach ($search_options as $key => $items) {
146+
if (!isset($items["hidden"]) || !$items["hidden"]) {
147+
echo text($items["title"]);
148+
}
149+
}
150+
}

0 commit comments

Comments
 (0)