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

Interactive way to query compilers (e.g. "What is the type of <my expression>?") #17505

Closed
expikr opened this issue Oct 13, 2023 · 4 comments
Closed

Comments

@expikr
Copy link
Contributor

expikr commented Oct 13, 2023

I'm tripping up with strings and pointers and comptime, and when I try to write a throwaway script to tell me what the types of certain expression are, the debug print statement itself errors out or just straight up crashes without printing any output whatsoever.

All I want to do is to be able to ask the compiler what is the type that it thinks my expression is, without dealing with the catch-22 of needing to know what that answer is in order to get it to print the answer in the first place.

@xdBronch
Copy link
Contributor

if this is just for learning purposes and not meant to be part of an program, you can use @compileLog
for example the statement @compileLog("this is a string literal"); you get the output

Compile Log Output:
@as(*const [24:0]u8, "this is a string literal")

@expikr
Copy link
Contributor Author

expikr commented Oct 13, 2023

Example: I have N string literals known at compile time that I would like to pass to a utility function that will loop through them.

Slices are great as they keep track of the length, so naturally I just make the function argument accept type [][]const u8.

But then no amount of coaxing at the call site, whether using slice notation or putting it through layers of pointer casting would let the function accept the type, so I have no idea whether the mistake is happening at the callsite or at the argument definition, the compiler error does not give any useful indication of what the type is supposed to be.

@IntegratedQuantum
Copy link
Contributor

I think the main problem here is that the error message isn't descriptive enough.
So I suggest that we try to figure out what the issue was in your example and then you can try to propose a better error message.

It's probably just a simple issue, like a forgotten const: []const []const u8 in the function type or a forgotten & at the callsite.
If you would share a bit more of your code, especially how you created the array of strings and how you passed it to the function, I can see if I can help you further.

Also: Next time it would be better to ask for help in one of zig's community spaces first. You'll usually get a faster answer there.

@Vexu
Copy link
Member

Vexu commented Oct 13, 2023

There is a proposal that would enable a feature like this to be added #615

@Vexu Vexu closed this as not planned Won't fix, can't repro, duplicate, stale Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants