-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Compiler asserts & crashes on multiline string containing CRLF line ending (mainly affects Windows) #12550
Comments
This does seem to be Windows only having tested on other platforms, so will come back to it once #12420 has been resolved, as those test fixes might just end up fixing this anyway. But if not will happily work on trying to debug this. |
does it compile if you run |
Doing that causes the same panic to happen (almost identical stack trace). |
So this was the issue in the end (finally had the time to do some more investigation), but not sure how it should deal with this (obviously a crash is not the right solution here). |
compile error is the ideal workaround is including this in your project's root * text=auto
*.zig text eol=lf |
I've managed to get something along the lines of this working locally: ...\build.zig:1:36: error: expected test, comptime, var decl, or container field, found 'carriage return'
const builtin = @import("builtin");
^
...\build.zig:1:36: note: invalid byte: '\r' Although the goal now is to flesh out the error message to make it more descriptive. Will clean up what I have later & make a PR in a bit. |
The more I think about this the more that I think an error is the wrong approach, especially when considering programmer intent & the first time user experience (especially for someone learning zig, or even learning to program using zig!). Our options are:
Note: It's multiline string literals in particular that make this a more nuanced problem. Option 1: Accept CRLF line-endings as-isBenefits:
Cons:
Conclusion: Option 2: Accept CRLF line-endings but convert to LF in programBenefits:
Cons:
Conclusion: On the other hand, the first-time user experience of zig is super important. It's the kind of program I wish I had when first setting-out into learning lower-level programming. Whilst the language itself is really cool, it's the tooling & the fact that you just need a single binary to build any zig (& C/C++!) from any platform, for any platform that really sets it apart from the rest. Imagine the case of a beginner programmer, someone wanting to contribute to a project for the first or maybe even just creating a simple program in notepad following a tutorial. They are likely using Windows, and don't necesarily know about different line-ending encodings yet. To me the idea that in the default case, zig would error creates such an unnecessary barrier to entry out of concern for an inredibly rare-edge case would be getting the priorities wrong. It's worth pointing at that with regards to the status quo, the documentation says that CRLF characters are OK but discouraged. Updating that to say the CRLF characters in multiline string literals will be encoded as LF characters would be fairly easy. Option 3: Accept CRLF line-endings, but error if found in multiline string literals.Pros:
Cons:
Conclusion: Option 4: Error on any occurence of "CR".Pros:
Cons:
Conclusion: However, a big part of zig's appeal to me is that fact that it's a great learning tool for aspiring lower-level programmers, who may not have that experience. I think stuff like this can introduce friction in a very non-intuitive way (which other language errors in this case?) that is unnessecary. |
Closing this as it's a dupe of #11414 However, also looking at ziglang/zig-spec#38:
Seems like option 2. |
Zig Version
0.10.0-dev.8439+4a98385b0
Steps to Reproduce
A simple build.zig containing:
will do the trick (just make sure line endings are CRLF).
Expected Behavior
Zig not to crash. Although not sure how it should deal with this case, should they be converted to LF line endings automatically or something else?
Actual Behavior
zig crashes with the following output:
The text was updated successfully, but these errors were encountered: