-
-
Notifications
You must be signed in to change notification settings - Fork 415
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
3 changed files
with
85 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## Fix compiler crash | ||
|
||
Previously the following code would cause the compiler to crash. Now it will display a helpful error message: | ||
|
||
```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") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters