Conversation
A contract constructor that takes `@self` (view) instead of `ref self` was
rejected with the generic `Got unexpected type.` and no source location, and
`self.ctor` was set before the mutability check — so an invalid constructor was
still registered as the contract's constructor.
Add a dedicated `ConstructorNotExternal` error ("A contract constructor must
take `ref self`, not `@self`.") with the constructor's location, and set
`self.ctor` only after the check passes.
PR SummaryLow Risk Overview The check runs in Reviewed by Cursor Bugbot for commit 436acee. Bugbot is set up for automated code reviews on this repo. Configure here. |
eytan-starkware
left a comment
There was a problem hiding this comment.
@eytan-starkware reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).

Summary
Adds a dedicated
ConstructorNotExternalABI error for the case where a contract constructor is declared withself: @ContractState(view/snapshot) instead ofref self: ContractState(external). Previously, this case fell through to a genericUnexpectedTypeerror, which gave no useful diagnostic information. The new error message explicitly states:"A contract constructor must take 'ref self', not '@self'."and correctly points to the constructor's source location in the diagnostic output.Type of change
Please check one:
Why is this change needed?
When a constructor was written with
self: @ContractStateinstead ofref self: ContractState, the compiler emitted a genericUnexpectedTypeerror with no indication of what was actually wrong or how to fix it. This made it difficult for developers to diagnose the issue.What was the behavior or documentation before?
A constructor declared with
self: @ContractStatewould fail ABI generation with the unhelpful errorUnexpectedType, and the source location was not attached to the error.What is the behavior or documentation after?
ABI generation now fails with the specific error:
The diagnostic correctly points to the constructor definition in the source file.
Related issue or discussion (if any)
N/A
Additional context
A new test case (
Test constructor taking '@self' (view) instead of 'ref self') has been added toabi_failuresto cover this scenario.