Closed wtholliday closed 10 months ago
I think this is intended behavior and not a bug, but maybe it should be changed.
It's never intended to get a segfault. Not sure how this one can be caught, since it's a runtime failure.
I guess there would have to be a wrapper around dereferencing that checks if the reference is valid.
If you plan to keep advertising “No null” on the home page, that implies the language should guarantee that safe code cannot even produce a null reference, like in Rust or Haskell. Achieving that guarantee requires careful language design (see also #10837 for maps, #14911 for arrays). But if you have that guarantee, checks on dereferencing should not be needed.
In this case, initializing &Node
with 0
should be forbidden. A tree-like structure should use an optional type ?&Node
for fields that may or may not point to a Node
. It looks like other fixes may be necessary to support that usage.
It is forbidden, it requires unsafe
. This particular issue is a bug where the unsafe check is not enforced.
Just some info: This is now a RUNTIME ERROR: invalid memory access
https://vosca.dev/p/2276f28ae1
@damywise That is how the V playground displays a segfault. Nothing’s changed.
Ah I see, I misunderstood then. Sorry about that
V version: V 0.3.0 f0cee25 OS: macOS 12.4 (21F79)
What did you do?
Compiled and ran the following program:
using:
What did you expect to see?
Runtime error for null de-reference, or compiler error disallowing initialization of reference to null.
What did you see instead?