sophiajt / june

MIT License
803 stars 31 forks source link

Dereferencing a none value silently crashes the program #67

Open antoniusnaumann opened 4 months ago

antoniusnaumann commented 4 months ago

Currently, accessing fields from optionals that are none silently crash the program. I would have expected the compiler to give an error when dereferencing an optional. Commit: f2107d499a722085ab64ff09cff8dc5e754880c0 (current main branch commit)

When running this program

struct Node {
    data: i64
    next: Node?
}

mut list = new Node(data: 1, next: new Node(data: 2, next: none))
println(list.next.data)

mut list2 = new Node(data: 0, next: none)

println(c"ALIVE")
println(list2.next.data)
println(c"DEAD")

it outputs

2
ALIVE

P.S.: I am aware that this project is in its early days, so if this issue is known or not relevant to the current state of this project, feel free to close it. I am curious to see how this project will evolve :)