ponylang / ponyc

Pony is an open-source, actor-model, capabilities-secure, high performance programming language
http://www.ponylang.io
BSD 2-Clause "Simplified" License
5.73k stars 415 forks source link

Fix compiler crash #4505

Closed ArthurPV closed 7 months ago

ArthurPV commented 7 months ago

Fix #4477

Before this PR this code didn't work and cause segmentation fault as reported in issue #4477:

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
ponylang-main commented 7 months ago

Hi @ArthurPV,

The changelog - fixed label was added to this pull request; all PRs with a changelog label need to have release notes included as part of the PR. If you haven't added release notes already, please do.

Release notes are added by creating a uniquely named file in the .release-notes directory. We suggest you call the file 4505.md to match the number of this pull request.

The basic format of the release notes (using markdown) should be:

## Title

End user description of changes, why it's important,
problems it solves etc.

If a breaking change, make sure to include 1 or more
examples what code would look like prior to this change
and how to update it to work after this change.

Thanks.

SeanTAllen commented 7 months ago

I've updated the release notes.

jemc commented 7 months ago

Thanks for doing this!

@SeanTAllen updated the release notes, and we'll merge it after the CI checks have all passed.

SeanTAllen commented 7 months ago

Thanks @ArthurPV. This will get merged once CI passes.

SeanTAllen commented 7 months ago

@ArthurPV this will be released at the end of the month. The weekend of the 27th/28th. It will be in tonight's nightly as well.