-
-
Notifications
You must be signed in to change notification settings - Fork 415
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
Segmentation fault when ponyc compiles this code #4477
Comments
This is invalid Pony code that the compiler isn't gracefully catching. |
The parts of the code that are invalid are the Specifically: The compiler should print a nice error message explaining this when the code is invalid. |
Before this PR this code didn't work and cause segmentation fault as reported in issue #4477: ```pony struct FFIBytes var ptr: Pointer[U8 val] = Pointer[U8].create() var length: USize = 0 fun iso string(): String val => recover String.from_cpointer(consume FFIBytes.ptr, consume FFIBytes.length) end actor Main new create(env: Env) => env.out.print("nothing to see here") ``` Now, with the changes in this PR, here's what the compiler generates as an error: ``` Building builtin -> /home/slacturyx/Programming/Personal/Github/ponyc/packages/builtin Building ./app -> /home/slacturyx/Programming/Personal/Github/ponyc/app Error: /home/slacturyx/Programming/Personal/Github/ponyc/app/app.pony:6:46: You can't consume an expression that isn't local. More specifically, you can only consume a local variable (a single lowercase identifier, with no dots) or a field of this (this followed by a dot and a single lowercase identifier). recover String.from_cpointer(consume FFIBytes.ptr, consume FFIBytes.length) end ^ Error: /home/slacturyx/Programming/Personal/Github/ponyc/app/app.pony:6:38: consuming a field is only allowed if it is reassigned in the same expression recover String.from_cpointer(consume FFIBytes.ptr, consume FFIBytes.length) end ^ Error: /home/slacturyx/Programming/Personal/Github/ponyc/app/app.pony:6:68: You can't consume an expression that isn't local. More specifically, you can only consume a local variable (a single lowercase identifier, with no dots) or a field of this (this followed by a dot and a single lowercase identifier). recover String.from_cpointer(consume FFIBytes.ptr, consume FFIBytes.length) end ^ Error: /home/slacturyx/Programming/Personal/Github/ponyc/app/app.pony:6:60: consuming a field is only allowed if it is reassigned in the same expression recover String.from_cpointer(consume FFIBytes.ptr, consume FFIBytes.length) end ``` Fixes #4477
I've been told multiple times that this looks like a compiler bug, and I agree, so I'm posting this here. The following code causes a segfault in the compiler:
I have honestly no idea what's going on to cause this. I've reproduced it on ponyc versions 0.49.0, 0.53.0, and 0.58.0. The latter two suggest creating an issue from the backtrace, but don't actually give one:
While ponyc 0.49.0 does provide a backtrace:
The text was updated successfully, but these errors were encountered: