Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove MixedAssignment #8776

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -863,3 +863,4 @@
- :information_source: migration possible using `Psalm\PluginFileExtensionsSocket`
- [BC] Method `\Psalm\Plugin\EventHandler\Event\AfterFunctionLikeAnalysisEvent::getClasslikeStorage()` was removed,
use correct `\Psalm\Plugin\EventHandler\Event\AfterFunctionLikeAnalysisEvent::getFunctionlikeStorage()` instead
- [BC] Issue `MixedAssignment` and its corresponding class `Psalm\Issue\MixedAssignment` was removed. Extraneous `@psalm-suppress MixedAssignment` annotations will now generate an `UnusedPsalmSuppress` issue if the `findUnusedPsalmSuppress` option is true or `--find-unused-psalm-suppress` is passed as a command-line flag.
2 changes: 1 addition & 1 deletion config.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,13 @@
<xs:element name="MixedArrayAssignment" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MixedArrayOffset" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MixedArrayTypeCoercion" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MixedAssignment" type="IssueHandlerType" minOccurs="0" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should remain here, but be marked as deprecated. See https://github.com/orklah/psalm/blob/24ae96b373cb44186c58360543dcf0987436df0c/config.xsd#L20-L25 for example

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, it doesn't seem like anyone references it in psalm.xml

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github search shows 97 entries, including some popular repos like doctrine/collections: https://github.com/search?q=path%3Apsalm.xml+language%3AXML+MixedAssignment&type=code

<xs:element name="MixedClone" type="ArgumentIssueHandlerType" minOccurs="0" />
<xs:element name="MixedFunctionCall" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MixedInferredReturnType" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MixedMethodCall" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MixedOperand" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MixedPropertyAssignment" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MixedPropertyAssignmentValue" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MixedPropertyFetch" type="IssueHandlerType" minOccurs="0" />
<xs:element name="MixedPropertyTypeCoercion" type="PropertyIssueHandlerType" minOccurs="0" />
<xs:element name="MixedReturnStatement" type="IssueHandlerType" minOccurs="0" />
Expand Down
2 changes: 1 addition & 1 deletion docs/running_psalm/issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@
- [MixedArrayAssignment](issues/MixedArrayAssignment.md)
- [MixedArrayOffset](issues/MixedArrayOffset.md)
- [MixedArrayTypeCoercion](issues/MixedArrayTypeCoercion.md)
- [MixedAssignment](issues/MixedAssignment.md)
- [MixedClone](issues/MixedClone.md)
- [MixedFunctionCall](issues/MixedFunctionCall.md)
- [MixedInferredReturnType](issues/MixedInferredReturnType.md)
- [MixedMethodCall](issues/MixedMethodCall.md)
- [MixedOperand](issues/MixedOperand.md)
- [MixedPropertyAssignment](issues/MixedPropertyAssignment.md)
- [MixedPropertyAssignmentValue](issues/MixedPropertyAssignmentValue.md)
- [MixedPropertyFetch](issues/MixedPropertyFetch.md)
- [MixedPropertyTypeCoercion](issues/MixedPropertyTypeCoercion.md)
- [MixedReturnStatement](issues/MixedReturnStatement.md)
Expand Down
2 changes: 2 additions & 0 deletions docs/running_psalm/issues/MixedAssignment.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# MixedAssignment

**This issue is deprecated in Psalm 5**

Emitted when assigning an unannotated variable to a value for which Psalm
cannot infer a type more specific than `mixed`.

Expand Down
16 changes: 16 additions & 0 deletions docs/running_psalm/issues/MixedPropertyAssignmentValue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# MixedPropertyAssignmentValue

Emitted when setting a property to a `mixed` type.

```php
<?php

class A {
private string $mixed = '';

public function setMixed(mixed $value): void
{
$this->mixed = $value;
}
}
```
4 changes: 2 additions & 2 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@
</errorLevel>
</PropertyTypeCoercion>

<MixedAssignment>
<MixedPropertyAssignmentValue>
<errorLevel type="suppress">
<directory name="vendor/nikic/php-parser" />
</errorLevel>
</MixedAssignment>
</MixedPropertyAssignmentValue>
</issueHandlers>
</psalm>
4 changes: 1 addition & 3 deletions src/Psalm/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ class Config
'MixedArrayAssignment',
'MixedArrayOffset',
'MixedArrayTypeCoercion',
'MixedAssignment',
'MixedFunctionCall',
'MixedInferredReturnType',
'MixedMethodCall',
'MixedOperand',
'MixedPropertyFetch',
'MixedPropertyAssignment',
'MixedPropertyAssignmentValue',
'MixedReturnStatement',
'MixedStringOffsetAssignment',
'MixedArgumentTypeCoercion',
Expand Down Expand Up @@ -943,7 +943,6 @@ private static function processConfigDeprecations(
* @param non-empty-string $file_contents
*
* @psalm-suppress MixedMethodCall
* @psalm-suppress MixedAssignment
* @psalm-suppress MixedArgument
* @psalm-suppress MixedPropertyFetch
*
Expand Down Expand Up @@ -2499,7 +2498,6 @@ private function setBooleanAttribute(string $name, bool $value): void
}

/**
* @psalm-suppress MixedAssignment
* @psalm-suppress MixedArrayAccess
*/
public function getPHPVersionFromComposerJson(): ?string
Expand Down
1 change: 0 additions & 1 deletion src/Psalm/Config/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ public static function getPaths(string $current_dir, ?string $suggested_dir): ar

/**
* @return list<string>
* @psalm-suppress MixedAssignment
* @psalm-suppress MixedArgument
*/
private static function getPsr4Or0Paths(string $current_dir, array $composer_json): array
Expand Down
1 change: 1 addition & 0 deletions src/Psalm/Config/IssueHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public static function getAllIssueTypes(): array
&& $issue_name !== 'PluginIssue'
&& $issue_name !== 'MixedIssue'
&& $issue_name !== 'MixedIssueTrait'
&& $issue_name !== 'MixedAssignment'
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Psalm\Internal\Analyzer\TraitAnalyzer;
use Psalm\Internal\Clause;
use Psalm\Internal\Scope\IfScope;
use Psalm\IssueBuffer;
use Psalm\Node\Expr\VirtualBooleanNot;
use Psalm\Type;
use Psalm\Type\Reconciler;
Expand Down Expand Up @@ -340,12 +339,6 @@ public static function analyze(
$codebase->analyzer->decrementMixedCount($statements_analyzer->getFilePath());
}
}

IssueBuffer::remove(
$statements_analyzer->getFilePath(),
'MixedAssignment',
$first_appearance->raw_file_start
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
use Psalm\Issue\InvalidPropertyAssignment;
use Psalm\Issue\InvalidPropertyAssignmentValue;
use Psalm\Issue\LoopInvalidation;
use Psalm\Issue\MixedAssignment;
use Psalm\Issue\MixedPropertyAssignment;
use Psalm\Issue\MixedPropertyAssignmentValue;
use Psalm\Issue\MixedPropertyTypeCoercion;
use Psalm\Issue\NoInterfaceProperties;
use Psalm\Issue\NullPropertyAssignment;
Expand Down Expand Up @@ -1419,7 +1419,7 @@ private static function analyzeAtomicAssignment(
}

IssueBuffer::maybeAdd(
new MixedAssignment(
new MixedPropertyAssignmentValue(
$message,
new CodeLocation($statements_analyzer->getSource(), $stmt),
$origin_location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
use Psalm\Issue\LoopInvalidation;
use Psalm\Issue\MissingDocblockType;
use Psalm\Issue\MixedArrayAccess;
use Psalm\Issue\MixedAssignment;
use Psalm\Issue\MixedPropertyAssignmentValue;
use Psalm\Issue\NoValue;
use Psalm\Issue\NullReference;
use Psalm\Issue\PossiblyInvalidArrayAccess;
Expand Down Expand Up @@ -381,12 +381,6 @@ public static function analyze(
$codebase = $statements_analyzer->getCodebase();

if ($assign_value_type->hasMixed()) {
$root_var_id = ExpressionIdentifier::getRootVarId(
$assign_var,
$statements_analyzer->getFQCLN(),
$statements_analyzer
);

if (!$context->collect_initializations
&& !$context->collect_mutations
&& $statements_analyzer->getFilePath() === $statements_analyzer->getRootFilePath()
Expand All @@ -397,10 +391,8 @@ public static function analyze(
$codebase->analyzer->incrementMixedCount($statements_analyzer->getFilePath());
}

if (!$assign_var instanceof PhpParser\Node\Expr\PropertyFetch
&& !strpos($root_var_id ?? '', '->')
if ($assign_var instanceof PhpParser\Node\Expr\StaticPropertyFetch
&& !$comment_type
&& strpos($var_id ?? '', '$_') !== 0
) {
$origin_locations = [];

Expand All @@ -426,7 +418,7 @@ public static function analyze(
}

IssueBuffer::maybeAdd(
new MixedAssignment(
new MixedPropertyAssignmentValue(
$message,
$issue_location,
$origin_location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -989,12 +989,6 @@ private static function processAssertFunctionEffects(
) {
$codebase->analyzer->decrementMixedCount($statements_analyzer->getFilePath());
}

IssueBuffer::remove(
$statements_analyzer->getFilePath(),
'MixedAssignment',
$first_appearance->raw_file_start
);
}

if (isset($op_vars_in_scope[$var_id])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -928,12 +928,6 @@ public static function applyAssertionsToContext(
) {
$codebase->analyzer->decrementMixedCount($statements_analyzer->getFilePath());
}

IssueBuffer::remove(
$statements_analyzer->getFilePath(),
'MixedAssignment',
$first_appearance->raw_file_start
);
}

$op_vars_in_scope[$var_id] = $op_vars_in_scope[$var_id]->setFromDocblock(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,6 @@ public static function analyze(
return true;
}

/**
* @psalm-suppress MixedAssignment
*/
public static function getPathTo(
PhpParser\Node\Expr $stmt,
?NodeDataProvider $type_provider,
Expand Down
1 change: 0 additions & 1 deletion src/Psalm/Internal/Cli/Psalm.php
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,6 @@ private static function restart(array $options, int $threads): void

if (isset($options['disable-extension'])) {
if (is_array($options['disable-extension'])) {
/** @psalm-suppress MixedAssignment */
foreach ($options['disable-extension'] as $extension) {
if (is_string($extension)) {
$ini_handler->disableExtension($extension);
Expand Down
1 change: 0 additions & 1 deletion src/Psalm/Internal/Cli/Psalter.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,6 @@ static function (string $line): bool {
private static function loadCodeownersFiles(array $desired_codeowners, array $codeowner_files): array
{
$paths_to_check = [];
/** @psalm-suppress MixedAssignment */
foreach ($desired_codeowners as $desired_codeowner) {
if (!is_string($desired_codeowner)) {
die('Invalid --codeowner ' . (string)$desired_codeowner . PHP_EOL);
Expand Down
3 changes: 0 additions & 3 deletions src/Psalm/Internal/CliUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ public static function requireAutoloaders(
return $first_autoloader;
}

/**
* @psalm-suppress MixedAssignment
*/
public static function getVendorDir(string $current_dir): string
{
$composer_json_path = Composer::getJsonFilePath($current_dir);
Expand Down
5 changes: 0 additions & 5 deletions src/Psalm/Internal/Fork/Pool.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ class Pool
* A closure to execute upon shutting down a child
* @param Closure(mixed $data):void $task_done_closure
* A closure to execute when a task is done
*
* @psalm-suppress MixedAssignment
*/
public function __construct(
Config $config,
Expand Down Expand Up @@ -326,9 +324,6 @@ private static function streamForChild(array $sockets)
* The results are returned in an array, one for each worker. The order of the results
* is not maintained.
*
*
* @psalm-suppress MixedAssignment
*
* @return list<mixed>
*/
private function readResultsFromChildren(): array
Expand Down
2 changes: 0 additions & 2 deletions src/Psalm/Internal/LanguageServer/EmitterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public function emit(
): void {
if ($continueCallBack === null) {
foreach ($this->listeners($eventName) as $listener) {
/** @psalm-suppress MixedAssignment */
$result = call_user_func_array($listener, $arguments);
if ($result === false) {
return;
Expand All @@ -92,7 +91,6 @@ public function emit(

foreach ($listeners as $listener) {
--$counter;
/** @psalm-suppress MixedAssignment */
$result = call_user_func_array($listener, $arguments);
if ($result === false) {
return;
Expand Down
1 change: 0 additions & 1 deletion src/Psalm/Internal/PluginManager/ComposerLock.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ private function getAllPluginPackages(): array
{
$packages = $this->getAllPackages();
$ret = [];
/** @psalm-suppress MixedAssignment */
foreach ($packages as $package) {
if ($this->isPlugin($package)) {
$ret[] = $package;
Expand Down
3 changes: 0 additions & 3 deletions src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ private function getCacheHash(?string $_unused_file_path, ?string $file_contents
return PHP_VERSION_ID >= 8_01_00 ? hash('xxh128', $data) : hash('md4', $data);
}

/**
* @psalm-suppress MixedAssignment
*/
private function loadFromCache(string $fq_classlike_name_lc, ?string $file_path): ?ClassLikeStorage
{
$cache_location = $this->getCacheLocationForClass($fq_classlike_name_lc, $file_path);
Expand Down