Skip to content

Are changes to the constructor really BC breaks? #497

Description

@ondrejmirtes

Hi, I've got these messages:

[BC] CHANGED: Default parameter value for parameter $nextAutoIndex of PHPStan\Type\Constant\ConstantArrayType#__construct() changed from 0 to array (
  0 => 0,
)
[BC] CHANGED: The parameter $nextAutoIndex of PHPStan\Type\Constant\ConstantArrayType#__construct() changed from int to a non-contravariant int|array
[BC] CHANGED: The parameter $nextAutoIndex of PHPStan\Type\Constant\ConstantArrayType#__construct() changed from int to int|array

This is how the PHP diff looks like:

 	/**
 	 * @api
 	 * @param array<int, ConstantIntegerType|ConstantStringType> $keyTypes
 	 * @param array<int, Type> $valueTypes
+	 * @param non-empty-list<int>|int $nextAutoIndexes
 	 * @param int[] $optionalKeys
 	 */
 	public function __construct(
 		private array $keyTypes,
 		private array $valueTypes,
-		private int $nextAutoIndex = 0,
+		int|array $nextAutoIndexes = [0],
 		private array $optionalKeys = [],
 	)
 	{
 		assert(count($keyTypes) === count($valueTypes));
 
+		if (is_int($nextAutoIndexes)) {
+			$nextAutoIndexes = [$nextAutoIndexes];
+		}
+
+		$this->nextAutoIndexes = $nextAutoIndexes;
+

I'm widening the type of the parameter, and if the argument is omitted from the call, or if the old type is passed to the parameter, the result is the same.

I don't see how this is a BC break, but I'm open to be corrected :) Thanks.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions