Skip to content

Answer maybe in ObjectType::isInstanceOf() where a subclass may be an instance - #7173

Merged
ondrejmirtes merged 2 commits into
2.3.xfrom
instance-of-disjointness
Nov 26, 2026
Merged

ondrejmirtes merged 2 commits into
2.3.xfrom
instance-of-disjointness

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

ObjectType::isInstanceOf() answered no where a subclass may be an instance of the asked class:

  • when the asked class is an interface and this class is a non-final class (a subclass may implement it - isSuperTypeOf() already answers maybe here), and
  • when the asked class is a final subclass of this class.

So is_iterable($stdClass) was reported as always false and narrowed to *NEVER*, $iterable instanceof stdClass was always false, and Exception&iterable was never, while $stdClass instanceof Traversable correctly gave stdClass&Traversable (non-monotone disjointness; it also made TypeCombinator::intersect() non-associative).

Errors that need an iterable (foreach, yield from, unpacking, iterable/Traversable parameters) still report a non-iterable DateTime - they require yes.

ConstantArrayType::isCallable() had the same non-monotonicity: list<int> was never callable while its subtype list{int, int} was maybe callable. A sealed [classOrObject, method] shape whose slots cannot hold object|string and string is now not callable, as the unsealed path already checked.

turbo-ext mirrors both changes.

… instance

- ObjectType::isInstanceOf() returned no when the asked class is an
  interface and this class is not an interface, although a subclass of a
  non-final class may implement it (isSuperTypeOf() already says maybe).
  It also returned no for a final subclass of this class. is_iterable() on
  stdClass, instanceof stdClass on iterable and Exception&iterable were
  narrowed to never.
- ConstantArrayType: a sealed [classOrObject, method] shape whose slots
  cannot hold an object or a string and a string is not callable, as the
  unsealed path already checks - list{int, int} was maybe callable while
  list<int> was not.
- turbo-ext: the same in ObjectType.cpp and ConstantArrayType.cpp.
- ObjectTypeTest/StaticTypeTest: DateTime may be iterable through a
  subclass; Closure (final) still is not.

Amp-Thread-ID: https://ampcode.com/threads/T-01a17eac-1199-74a6-b3f7-dfbd8a084465
…r objects

The check that the [classOrObject, method] slots can hold a callable
compared them with isSuperTypeOf() against object|string and string.
Both directions answer no for every slot type the check meets, so
mutation testing could not tell them apart. isObject()/isString() ask
the same question directly.

New cases cover a slot that may be an object or a string (int|object,
int|string) and a method slot that may be a string (int|string).

turbo-ext: the same in ConstantArrayType.cpp.

Amp-Thread-ID: https://ampcode.com/threads/T-01a17eac-1199-74a6-b3f7-dfbd8a084465
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant