Skip to content

fix: call mark_as_used() for classes referenced only in instanceof (#68)#1557

Closed
KorsarOfficial wants to merge 1 commit intoVKCOM:masterfrom
KorsarOfficial:bugfix/issue-68-instanceof-unused-class
Closed

fix: call mark_as_used() for classes referenced only in instanceof (#68)#1557
KorsarOfficial wants to merge 1 commit intoVKCOM:masterfrom
KorsarOfficial:bugfix/issue-68-instanceof-unused-class

Conversation

@KorsarOfficial
Copy link

Problem

When a class appeared only in an instanceof expression and was never instantiated or used as a value anywhere else in the file, the code-gen pass crashed trying to include the class header — but the header had never been written because mark_as_used() was never called for that class.

This is the same bug pattern already fixed for op_catch: the catch-clause handling in CalcFuncDepPass::on_enter_vertex calls mark_as_used() precisely to handle this case, but the identical path through op_instanceof was missing the call.

Fix

In compiler/pipes/calc-func-dep.cpp, add mark_as_used() for the class resolved in an instanceof expression, mirroring the existing op_catch pattern.

Tests

  • tests/phpt/interfaces/135_instanceof_unused_class.php — basic regression
  • tests/phpt/interfaces/136_instanceof_only_in_condition.php — additional coverage: class only referenced via instanceof, never instantiated

Closes #68

…KCOM#68)

When a class appeared only in an `instanceof` expression and was never
instantiated anywhere else, the code-gen pass tried to include its
generated header but the header had never been written, causing a crash.

The fix mirrors the identical pattern already applied to `op_catch`:
call `mark_as_used()` so the class header gets generated even when the
class is never used as a value.

Also adds two regression tests:
- tests/phpt/interfaces/135_instanceof_unused_class.php
- tests/phpt/interfaces/136_instanceof_only_in_condition.php
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.

Compilation failure for unused class used in instanceof expr

1 participant