Skip to content

fix[codegen]: assert staticcall in constant context#5090

Open
banteg wants to merge 2 commits into
vyperlang:masterfrom
banteg:fix/venom-staticcall-assert
Open

fix[codegen]: assert staticcall in constant context#5090
banteg wants to merge 2 commits into
vyperlang:masterfrom
banteg:fix/venom-staticcall-assert

Conversation

@banteg

@banteg banteg commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

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 derived use_staticcall from the target's mutability but never cross-checked it against the enclosing context's constancy — a frontend miss would silently emit CALL instead of failing loudly in codegen.

How I did it

Added the equivalent two-line assert in Expr._lower_external_call, immediately after use_staticcall is derived and before the CALL/STATICCALL dispatch. VenomCodegenContext.is_constant() mirrors legacy Context.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/ and test_interfaces.py under --experimental-codegen.

Commit message

legacy external-call lowering asserts at codegen time that a constant
(view/pure or range-expression) context only emits staticcall. the
venom lowering derived `use_staticcall` from the target's mutability
but never cross-checked it against the enclosing context's constancy,
so a frontend miss would silently emit CALL instead of failing loudly.

add the equivalent assert to the venom external-call lowering,
matching the legacy message.

the assert is unreachable by construction; this is defense-in-depth
parity.

Description for the changelog

Fix: Venom external-call lowering asserts that constant contexts only emit STATICCALL, matching legacy defense-in-depth.

Cute Animal Picture

cute animal

@charles-cooper charles-cooper changed the title fix[venom]: assert staticcall in constant context chore[codegen]: assert staticcall in constant context Jun 15, 2026
@charles-cooper charles-cooper changed the title chore[codegen]: assert staticcall in constant context fix[codegen]: assert staticcall in constant context Jun 15, 2026
@charles-cooper charles-cooper enabled auto-merge (squash) June 15, 2026 17:30
@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.93%. Comparing base (242a4fa) to head (359fdba).
⚠️ Report is 8 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread vyper/codegen_venom/expr.py Outdated
auto-merge was automatically disabled June 22, 2026 12:32

Head branch was pushed to by a user without write access

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.

Venom: external calls in constant context lack staticcall sanity assert

2 participants