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

type of #expr argument in macro @a(int #expr) is ignored #1790

Open
Book-reader opened this issue Jan 6, 2025 · 1 comment
Open

type of #expr argument in macro @a(int #expr) is ignored #1790

Book-reader opened this issue Jan 6, 2025 · 1 comment
Labels
Bug Something isn't working Fixed Needs Verification Fixed, but needs verification that it works
Milestone

Comments

@Book-reader
Copy link
Contributor

the type should probably be either checked or disallowed.

fn void main()
{
  @a("hello");
}

macro @a(int #expr)
{
  io::printfn("Type of #expr was %s", $typeof(#expr).nameof);
}
 ~/code/c3 ❯ c3c compile-run test.c3

Program linked to executable 'test'.
Launching ./test
Type of #expr was String
Program completed with exit code 0.
@lerno
Copy link
Collaborator

lerno commented Jan 6, 2025

This requires some change in the behaviour of #foo parameters.

  1. Keep as today, but disallow compile time variable mutation (e.g. $a += 1 would not be accepted). This can be somewhat fragile and hard to track, but might work.
  2. Keep as today but completely disallow compile time variables inside
  3. Remove typing
  4. Make #foo arguments always evaluate ONCE as a check, then this evaluation is copied 0 to n times, without actually evaluation compile time arguments again. This would mean that $a += 1 would evaluate exactly once regardless whether #foo is used or not. There are some possible questions as to whether this would remove some flexibility in foo.#bar constructs, but likely that would be possible to handle.

One of these should be selected, as otherwise the semantics will be hard to figure out for a reader, and it would be easy to make mistakes.

@lerno lerno added this to the 0.7 milestone Jan 7, 2025
@lerno lerno added the Bug Something isn't working label Jan 7, 2025
@lerno lerno modified the milestones: 0.7, 0.6.6 Jan 9, 2025
@lerno lerno added the Fixed Needs Verification Fixed, but needs verification that it works label Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Fixed Needs Verification Fixed, but needs verification that it works
Projects
None yet
Development

No branches or pull requests

2 participants