Skip to content

fix[lang]: fix errors when shadowing a built-in - #5198

Open
Sporarum wants to merge 4 commits into
vyperlang:masterfrom
Sporarum:better-built-in-collision-errors
Open

Sporarum wants to merge 4 commits into
vyperlang:masterfrom
Sporarum:better-built-in-collision-errors

Conversation

@Sporarum

@Sporarum Sporarum commented Jul 22, 2026 •

Copy link
Copy Markdown
Collaborator

What I did

Improve error messages when trying to shadow a built-in:

Before:

int128: Bytes[3]
# NamespaceCollision: 'int128' has already been declared as a int128

def foo():
    msg: bool = True
    # NamespaceCollision: 'msg' has already been declared as a VarInfo(typ=msg, location=<DataLocation.UNSET: 'unset'>, modifiability=<Modifiability.RUNTIME_CONSTANT: 'runtime_constant'>, is_public=False, decl_node=None)

After:

int128: Bytes[3]
# NamespaceCollision: 'int128' is already the name of a built-in

def foo():
    msg: bool = True
    # NamespaceCollision: 'msg' is already the name of a built-in

How I did it

When there is a name collision, check if the previous definition has a source location, if it doesn't: it must be a built-in.

How to verify it

pytest
New tests added

Commit message

before this commit, the error message users got when trying to override
a built-in contained the __repr__ of the node, which was very noisy.
instead this commit uses a bespoke error message for these cases.

Description for the changelog

Improve error message when trying to shadow a built-in

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

@github-actions

Copy link
Copy Markdown

Gas Changes

No changes detected.

Summary

  • Total tests measured: 560
  • Changed: 0
  • Regressions (gas up): 0
  • Improvements (gas down): 0
  • New tests: 0
  • Deleted tests: 0
  • Newly failing: 0
  • Newly passing: 0

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4d41ed683a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vyper/semantics/namespace.py
@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

📊 Bytecode Size Changes (venom)

No changes detected.

Full bytecode sizes

Contract legacy-O2 legacy-Os -O2 -O3 -Os
curvefi/legacy/CurveStableSwapMetaNG.vy 24952 23578 20233 19479 18926
curvefi/amm/stableswap/meta_implementation/meta_implementation_v_700.vy 23610 22805 20142 19072 18831
curvefi/amm/stableswap/implementation/implementation_v_700.vy 24962 23769 19506 18676 18276
curvefi/legacy/CurveStableSwapNG.vy 24473 23298 19070 18286 17896
curvefi/amm/tricryptoswap/implementation/implementation_v_200.vy 20724 19959 17385 16851 16459
curvefi/amm/twocryptoswap/implementation/implementation_v_210.vy 17634 16894 15128 14530 14197
yearnfi/VaultV3.vy 19972 19063 14901 13980 13429
curvefi/legacy/CurveCryptoSwap2.vy 18947 18382 14719 14229 14054
yearnfi/VaultV2.vy 16676 15763 13335 12543 12126
curvefi/amm/stableswap/factory/factory_v_100.vy 14558 13978 12055 10863 10963
curvefi/gauge/child_gauge/implementation/implementation_v_110.vy 12338 11561 10033 9376 8987
curvefi/gauge/child_gauge/implementation/implementation_v_100.vy 12017 11249 9764 9114 8728
curvefi/amm/stableswap/views/views_v_120.vy 12784 12368 9697 9074 9285
curvefi/amm/tricryptoswap/math/math_v_200.vy 11189 11126 8993 7941 8134
curvefi/legacy/CurveCryptoMathOptimized3.vy 11188 11125 8992 7941 8134
curvefi/gauge/child_gauge/implementation/implementation_v_020.vy 10665 9947 8860 8274 7888
curvefi/registries/metaregistry/metaregistry_v_110.vy 7590 6732 6523 5742 5635
curvefi/helpers/router/router_v_110.vy 6717 6717 6495 5977 6279
curvefi/amm/tricryptoswap/views/views_v_200.vy 7821 7776 6247 6036 6181
curvefi/helpers/stable_swap_meta_zap/stable_swap_meta_zap_v_100.vy 7302 7067 6193 5706 5926
curvefi/amm/twocryptoswap/views/views_v_200.vy 6991 6946 5807 5610 5741
curvefi/registries/metaregistry/registry_handlers/stableswap/handler_v_110.vy 6633 6259 5696 4851 5401
curvefi/amm/twocryptoswap/math/math_v_210.vy 6800 6800 5506 5012 5039
curvefi/amm/twocryptoswap/factory/factory_v_200.vy 5540 5252 4790 3970 4104
curvefi/amm/tricryptoswap/factory/factory_v_200.vy 5246 5021 4649 3936 4066
curvefi/gauge/child_gauge/factory/factory_v_201.vy 4844 4547 4092 3806 3642
curvefi/registries/metaregistry/registry_handlers/tricryptoswap/handler_v_110.vy 4241 3939 3761 3410 3472
curvefi/registries/metaregistry/registry_handlers/twocryptoswap/handler_v_110.vy 4186 3884 3701 3281 3359
curvefi/gauge/child_gauge/factory/factory_v_100.vy 4183 3914 3594 3270 3097
yearnfi/VaultFactory.vy 3765 3617 3150 2250 2555
curvefi/registries/address_provider/address_provider_v_201.vy 2973 2782 2631 2427 2339
curvefi/helpers/rate_provider/rate_provider_v_101.vy 3260 3260 2570 2298 2331
curvefi/amm/stableswap/math/math_v_100.vy 3067 3046 2442 2237 2293
curvefi/helpers/rate_provider/rate_provider_v_100.vy 2847 2841 2326 2007 2027
curvefi/helpers/deposit_and_stake_zap/deposit_and_stake_zap_v_100.vy 2322 2316 1883 1712 1771
curvefi/governance/relayer/taiko/relayer_v_001.vy 2068 2064 1766 1545 1593
curvefi/governance/relayer/polygon_cdk/relayer_v_101.vy 1556 1523 1554 1348 1371
curvefi/governance/relayer/arb_orbit/relayer_v_101.vy 1266 1262 1253 1077 1126
curvefi/governance/relayer/op_stack/relayer_v_101.vy 1186 1182 1194 1025 1067
curvefi/governance/relayer/not_rollup/relayer_v_100.vy 1168 1153 1185 1022 1048
curvefi/governance/vault/vault_v_100.vy 964 941 873 834 850
curvefi/governance/relayer/relayer_v_100.vy 496 496 593 490 503
curvefi/governance/agent/agent_v_100.vy 541 541 425 397 401
curvefi/governance/agent/agent_v_101.vy 541 541 425 397 401

Comment thread vyper/semantics/analysis/base.py
Comment thread vyper/semantics/analysis/module.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b9b286a3f6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 95 to +96
if prev_decl is None:
msg += f" as a {prev}"
msg = f"'{attr}' is already the name of a built-in"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Don't classify JSON ABI imports as built-ins

When the previous namespace entry is a JSON ABI import, this branch still reports the collision as a built-in: the .json import path returns InterfaceT.from_json_abi(...), and that factory builds the interface with decl_node=None, so import foo as X followed by another X declaration or alias now emits "'X' is already the name of a built-in". The fresh evidence after the earlier import fix is that only .vy imports were wrapped with an alias decl node; JSON ABI imports still have no declaration node, so this heuristic remains inaccurate for them.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the fix for this would be to populate decl_node for things comming from JSON ABIs, as this would also allow us to provide location for error messages involving members from json abis

This branch has not been deployed

No deployments
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.

2 participants