fix[codegen]: assert staticcall in constant context#5090
Open
banteg wants to merge 2 commits into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5090 +/- ##
=======================================
Coverage 92.93% 92.93%
=======================================
Files 188 188
Lines 27840 27843 +3
Branches 4831 4832 +1
=======================================
+ Hits 25874 25877 +3
Misses 1315 1315
Partials 651 651 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Sporarum
reviewed
Jun 22, 2026
auto-merge was automatically disabled
June 22, 2026 12:32
Head branch was pushed to by a user without write access
Sporarum
approved these changes
Jun 22, 2026
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.
What I did
Fixes #5060.
Legacy external-call lowering carries a codegen-layer sanity assert that a constant (view/pure, or range-expression) context can only emit
STATICCALL(vyper/codegen/external_call.py:assert use_staticcall, "typechecker missed this"). The Venom external-call lowering deriveduse_staticcallfrom the target's mutability but never cross-checked it against the enclosing context's constancy — a frontend miss would silently emitCALLinstead of failing loudly in codegen.How I did it
Added the equivalent two-line assert in
Expr._lower_external_call, immediately afteruse_staticcallis derived and before the CALL/STATICCALL dispatch.VenomCodegenContext.is_constant()mirrors legacyContext.is_constant()semantics (per-function constancy from view/pure mutability, plus forced constancy inside range expressions). The assert message matches legacy verbatim for greppability.How to verify it
The assert is unreachable by construction (semantic analysis rejects state-mutating external calls in constant contexts), matching the untested legacy assert — this is defense-in-depth parity. Suites pass:
tests/unit/compiler/,tests/functional/codegen/calling_convention/andtest_interfaces.pyunder--experimental-codegen.Commit message
Description for the changelog
Fix: Venom external-call lowering asserts that constant contexts only emit
STATICCALL, matching legacy defense-in-depth.Cute Animal Picture