Skip to content

Commit 0ffb833

Browse files
committed
Fix #2677 - use better assertion for null coalesce
1 parent 0f659d9 commit 0ffb833

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOpAnalyzer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ function (\Psalm\Internal\Clause $c) use ($mixed_var_ids) {
778778

779779
if ($stmt_left_type = $statements_analyzer->node_data->getType($stmt->left)) {
780780
$if_return_type_reconciled = AssertionReconciler::reconcile(
781-
'!null',
781+
'isset',
782782
clone $stmt_left_type,
783783
'',
784784
$statements_analyzer,

tests/AnnotationTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,16 @@ function foo(array $_bar) : void { }
10611061
/** @param list<scalar|array|object|resource|null> $_s */
10621062
function foo(array $_s) : void { }'
10631063
],
1064+
'possiblyUndefinedObjectProperty' => [
1065+
'<?php
1066+
function consume(string $value): void {
1067+
echo $value;
1068+
}
1069+
1070+
/** @var object{value?: string} $data */
1071+
$data = json_decode("{}", false);
1072+
consume($data->value ?? "");'
1073+
],
10641074
];
10651075
}
10661076

0 commit comments

Comments
 (0)