fix: call mark_as_used() for classes referenced only in instanceof (#68)#1557
Closed
KorsarOfficial wants to merge 1 commit intoVKCOM:masterfrom
Closed
fix: call mark_as_used() for classes referenced only in instanceof (#68)#1557KorsarOfficial wants to merge 1 commit intoVKCOM:masterfrom
KorsarOfficial wants to merge 1 commit intoVKCOM:masterfrom
Conversation
…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
2778c29 to
ba6e654
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a class appeared only in an
instanceofexpression 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 becausemark_as_used()was never called for that class.This is the same bug pattern already fixed for
op_catch: the catch-clause handling inCalcFuncDepPass::on_enter_vertexcallsmark_as_used()precisely to handle this case, but the identical path throughop_instanceofwas missing the call.Fix
In
compiler/pipes/calc-func-dep.cpp, addmark_as_used()for the class resolved in aninstanceofexpression, mirroring the existingop_catchpattern.Tests
tests/phpt/interfaces/135_instanceof_unused_class.php— basic regressiontests/phpt/interfaces/136_instanceof_only_in_condition.php— additional coverage: class only referenced via instanceof, never instantiatedCloses #68