Skip to content

Commit

Permalink
Emit MixedMethodCall when calling new on object
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Nov 19, 2022
1 parent d756191 commit 6554aa0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Expand Up @@ -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',
Expand All @@ -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(
Expand Down
20 changes: 10 additions & 10 deletions tests/ClassTest.php
Expand Up @@ -804,15 +804,6 @@ abstract class C implements I {}
'$o2===' => 'stdClass',
],
],
'newOnObject' => [
'code' => '<?php
/** @var object $o */;
$o2 = new $o;
',
'assertions' => [
'$o2===' => 'object',
],
],
'newOnObjectOfAnonymousClass' => [
'code' => '<?php
function f(): object {
Expand Down Expand Up @@ -1207,7 +1198,16 @@ class Foo
class Bar {}
',
'error_message' => 'ReservedWord',
]
],
'newOnObject' => [
'code' => '<?php
function f(object $o): object
{
return new $o;
}
',
'error_message' => 'MixedMethodCall',
],
];
}
}

0 comments on commit 6554aa0

Please sign in to comment.