From 6554aa05a78c1f9e4312883e77e2a2135760408e Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Sat, 19 Nov 2022 17:29:35 -0400 Subject: [PATCH] Emit `MixedMethodCall` when calling `new` on `object` --- .../Expression/Call/NewAnalyzer.php | 8 ++++---- tests/ClassTest.php | 20 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NewAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NewAnalyzer.php index 9f9613017f0..e730978924b 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NewAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NewAnalyzer.php @@ -849,7 +849,9 @@ private static function analyzeConstructorExpression( )) { // fall through } - } elseif ($lhs_type_part instanceof TMixed) { + } elseif ($lhs_type_part instanceof TMixed + || $lhs_type_part instanceof TObject + ) { IssueBuffer::maybeAdd( new MixedMethodCall( 'Cannot call constructor on an unknown class', @@ -865,9 +867,7 @@ private static function analyzeConstructorExpression( && $stmt_class_type->ignore_nullable_issues ) { // do nothing - } elseif ($lhs_type_part instanceof TObject - || $lhs_type_part instanceof TNamedObject - ) { + } elseif ($lhs_type_part instanceof TNamedObject) { $new_type = Type::combineUnionTypes($new_type, new Union([$lhs_type_part])); continue; } elseif (IssueBuffer::accepts( diff --git a/tests/ClassTest.php b/tests/ClassTest.php index e36af617329..001dc5b5a87 100644 --- a/tests/ClassTest.php +++ b/tests/ClassTest.php @@ -804,15 +804,6 @@ abstract class C implements I {} '$o2===' => 'stdClass', ], ], - 'newOnObject' => [ - 'code' => ' [ - '$o2===' => 'object', - ], - ], 'newOnObjectOfAnonymousClass' => [ 'code' => ' 'ReservedWord', - ] + ], + 'newOnObject' => [ + 'code' => ' 'MixedMethodCall', + ], ]; } }