Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
The contract plugin emitted bare prelude type names (Array, Span, Option) in generated code. A user type sharing one of those names inside the contract module shadows the prelude, breaking compilation (E2163). Qualify every emission to core::array::Array, core::array::Span, core::option::Option (and Option::Some/None, ArrayTrait::new), matching the existing convention. Fixes #10128. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
10729a1 to
2af8f3e
Compare
PR SummaryMedium Risk Overview Codegen templates in Reviewed by Cursor Bugbot for commit 2af8f3e. Bugbot is set up for automated code reviews on this repo. Configure here. |
TomerStarkware
left a comment
There was a problem hiding this comment.
@TomerStarkware reviewed 35 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on eytan-starkware).

Summary
The
#[starknet::contract]plugin now fully-qualifies the prelude types itemits in generated code (
core::array::Array,core::array::Span,core::option::Option, plusOption::Some/Option::Noneandcore::array::ArrayTrait::new) instead of relying on the bare prelude names.Touched codegen sites:
derive/event.rs— struct & enumEventimpls (append_keys_and_data/deserialize) and the flat/nested variant deserialization.entry_point.rs— entry-point wrapper signature (Span) andArrayTrait::new.dispatcher.rs— forward-method wrapper signature (Span).Adds a regression test (
shadowed_prelude_types) covering a contract thatdefines
Array,Span, andOptionuser types, and regenerates the affectedplugin_test_datagolden files.Type of change
Why is this change needed?
Cairo has a single flat namespace, so a user type defined inside a contract
module that shares a name with a prelude type shadows that prelude name. Because
the generated code referenced the bare names (e.g.
Array<felt252>), a userstruct Array {}(0 generic params) made the generatedArray<felt252>resolveto the user struct, producing:
This happened even for a storage-only contract with no entry points — the
auto-derived empty
Eventimpl alone references the bare prelude types. Thediagnostic gave no hint that the user's type name was the cause.
Fixes #10128.
What was the behavior before?
failed to compile with
error[E2163]: Expected 0 generic arguments, found 1(same for
OptionandSpan).What is the behavior after?
The contract compiles. Generated code fully-qualifies every prelude type it
references, so a same-module user type sharing the name can no longer shadow it.
Additional context
Removing the bare reference also surfaced a now-redundant
use core::array::ArrayTrait;incairo_level_tests/l2_to_l1_messages.cairo(it was only being consumed by the previously-bare generated
ArrayTrait::new()),which has been dropped.
This is scoped to the prelude-type axis named in the issue and is distinct
from parameter-name collisions (e.g.
__calldata__,component,serialized,value).