Skip to content

fix: correct line number reporting for missing CHECK errors on duplic…#3918

Closed
ayushmishra2005 wants to merge 3 commits intosolana-foundation:masterfrom
ayushmishra2005:added_missing_check
Closed

fix: correct line number reporting for missing CHECK errors on duplic…#3918
ayushmishra2005 wants to merge 3 commits intosolana-foundation:masterfrom
ayushmishra2005:added_missing_check

Conversation

@ayushmishra2005
Copy link
Copy Markdown

  • Fix safety_checks() method to iterate through structs explicitly instead of using generic unsafe_struct_fields()
  • Add struct name to error messages for better context when duplicate field names exist
  • Remove unused unsafe_struct_fields() method
  • Update test expectations to match new error message format

Fixes #3915

…ate account names

- Fix safety_checks() method to iterate through structs explicitly instead of using generic unsafe_struct_fields()
- Add struct name to error messages for better context when duplicate field names exist
- Remove unused unsafe_struct_fields() method
- Update test expectations to match new error message format

Fixes solana-foundation#3915
@vercel
Copy link
Copy Markdown

vercel bot commented Sep 7, 2025

@ayushmishra2005 is attempting to deploy a commit to the Solana Foundation Team on Vercel.

A member of the Team first needs to authorize it.

@jamie-osec jamie-osec added the lang label Oct 7, 2025
Copy link
Copy Markdown
Collaborator

@0x4ka5h 0x4ka5h left a comment

Choose a reason for hiding this comment

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

@ayushmishra2005, thanks for the contribution. When I run the tests by creating duplicate accounts, the compiler shows the below error instead of pointing to correct line.

--> programs/duplicate-names/src/lib.rs:5:1
  |
5 | #[program]
  | ^^^^^^^^^^
  |
  = help: message: Safety checks failed: 
                  /Users/0x4ka5h/Documents/intern/osec/development/anchor/tests/safety-checks/programs/duplicate-names/src/lib.rs:5:0
                  Struct field "my_account" in struct "FuncTwo" is unsafe, but is not documented.
                  Please add a `/// CHECK:` doc comment explaining why no checks through types are necessary.
                  Alternatively, for reasons like quick prototyping, you may disable the safety checks
                  by using the `skip-lint` option.
                  See https://www.anchor-lang.com/docs/the-accounts-struct#safety-checks for more information.

Could you please make sure the changes works as expected and please try to add a test to verify the changes are working and setup CI workflow too.

@ayushmishra2005
Copy link
Copy Markdown
Author

@ayushmishra2005, thanks for the contribution. When I run the tests by creating duplicate accounts, the compiler shows the below error instead of pointing to correct line.

--> programs/duplicate-names/src/lib.rs:5:1
  |
5 | #[program]
  | ^^^^^^^^^^
  |
  = help: message: Safety checks failed: 
                  /Users/0x4ka5h/Documents/intern/osec/development/anchor/tests/safety-checks/programs/duplicate-names/src/lib.rs:5:0
                  Struct field "my_account" in struct "FuncTwo" is unsafe, but is not documented.
                  Please add a `/// CHECK:` doc comment explaining why no checks through types are necessary.
                  Alternatively, for reasons like quick prototyping, you may disable the safety checks
                  by using the `skip-lint` option.
                  See https://www.anchor-lang.com/docs/the-accounts-struct#safety-checks for more information.

Could you please make sure the changes works as expected and please try to add a test to verify the changes are working and setup CI workflow too.

I have addressed this.

@0x4ka5h
Copy link
Copy Markdown
Collaborator

0x4ka5h commented Oct 30, 2025

Thanks for the update here!
CI workflow tests are added but the error didnt showing up with correct line whereas the pr itself is for fix: correct line number ....
Take the following info as inputs and please made changes.

Including file path, line, column and struct name is helpful in error, since its still pointing out to #[program]
Constrain test.sh with line number

Copy link
Copy Markdown
Collaborator

@0x4ka5h 0x4ka5h left a comment

Choose a reason for hiding this comment

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

please take a look at the above comment

@nutafrost
Copy link
Copy Markdown
Collaborator

The fix: correct line number reporting for missing CHECK is mentioned in #4032

@nutafrost nutafrost closed this Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Missing CHECK error gives wrong line number on dupe account name in same file

4 participants