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

Generic tag reported to be incompatible when correct for child generic classes #2295

Closed
calebdw opened this issue Jun 14, 2023 · 4 comments · Fixed by #2310
Closed

Generic tag reported to be incompatible when correct for child generic classes #2295

calebdw opened this issue Jun 14, 2023 · 4 comments · Fixed by #2310
Labels

Comments

@calebdw
Copy link

calebdw commented Jun 14, 2023

Hello!

I'm experiencing a problem similar to #2262, but this time when making child classes generic:

Code Example:

<?php

namespace Phpactor;

abstract class Model
{
}

/** @template TModel of \Phpactor\Model */
class Factory
{
}

/**
 * @template TModel of \Phpactor\Schedule
 * @extends Factory<TModel>
 */
class ScheduleFactory extends Factory
{
}

class Schedule extends Model
{
}

/** @extends ScheduleFactory<ChildSchedule> */
class ChildScheduleFactory extends ScheduleFactory
{
}

class ChildSchedule extends Schedule
{
}

From PHPStan:
image

Thanks!

@calebdw
Copy link
Author

calebdw commented Jan 15, 2024

@dantleech, this was fixed but started reporting again...was there a regression?

image

@dantleech
Copy link
Collaborator

dantleech commented Jan 15, 2024

the tests would indicate that it's fine:

yield new DiagnosticExample(
title: 'extend with typed templated argument',
source: <<<'PHP'
<?php
abstract class Model {}
class Schedule extends Model {}
/** @template TModel of Model */
class Factory {}
/**
* @template TModel of Schedule
* @extends Factory<TModel>
*/
class ScheduleFactory extends Factory {}
PHP,
valid: true,
assertion: function (Diagnostics $diagnostics): void {
Assert::assertCount(0, $diagnostics);
}
);

maybe something else changed on your side? or the test doesn't cover your case?

@calebdw
Copy link
Author

calebdw commented Jan 15, 2024

That looks like the test for #2262, but this is a separate case. The test does not give me any issues

@calebdw
Copy link
Author

calebdw commented Jan 15, 2024

This should produce a failing test:

<?php

namespace Phpactor;

abstract class Model {}

class Schedule extends Model {}

/** @template TModel of \Phpactor\Model */
class Factory {}

/**
 * @template TModel of Schedule
 * @extends Factory<TModel>
 */
class ScheduleFactory extends Factory {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants