Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing safety comments in code being unquoted into top-level item results in failure to parse #6968

Closed
TomAFrench opened this issue Jan 7, 2025 · 0 comments · Fixed by #6969
Assignees

Comments

@TomAFrench
Copy link
Member

This was first noted by @kashbrti.

The snippet below is expected to insert a test function into the program which consists of an empty unsafe block.

#[make_test]
pub mod foo {}

comptime fn make_test(_m: Module) -> Quoted {
    quote {
#[test]
fn bar() {
    unsafe { }
}
}
}

Running nargo test however produces the below output (and no test is inserted as shown by the final lines)

$ nargo test
warning: Failed to parse macro's token stream into top-level item
  ┌─ src/main.nr:1:1
  │
1 │ #[make_test]
  │ ------------
  │ │
  │ Unsafe block must start with a safety comment: //@safety
  │ Missing Safety Comment
  │
  = The resulting token stream was: (stream starts on next line)
      #[test]fn bar() {
        unsafe {
            
        }
    }
  = To avoid this error in the future, try adding input validation to your macro. Erroring out early with an `assert` can be a good way to provide a user-friendly error message

[tmep] Running 0 test functions
[tmep] 0 tests passed

We should find out why this warning results in the macro failing to insert this function and fix it. We should also throw a hard error if we reach a situation where we're not properly unquoting values like this as opposed to failing silently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants