vtereshkov / umka-lang

Umka: a statically typed embeddable scripting language
BSD 2-Clause "Simplified" License
1k stars 53 forks source link

No error on dereferencing null weak pointer #384

Closed vtereshkov closed 2 months ago

vtereshkov commented 2 months ago

In the playground:

type S = struct {
        x, y: int
}

type T = struct {
        ws: weak ^S
}

fn main() {
        s := &S{5, 7}
        t := T{s}
        t.ws = null
        a := t.ws.x
        printf("%v\n", a) // 68719476738
}
vtereshkov commented 2 months ago
t.ws = null

000000034     12               PUSH_LOCAL_PTR -56
000000035     12                         PUSH int 0
000000036     12                   WEAKEN_PTR
000000037     12        CHANGE_REF_CNT_ASSIGN weak ^S

a := t.ws.x

000000038     13                   PUSH_LOCAL ^ -56
000000039     13               STRENGTHEN_PTR
000000040     13                        DEREF int
000000041     13               PUSH_LOCAL_PTR -64
000000042     13                 SWAP; ASSIGN int 8
vtereshkov commented 2 months ago
type S = struct {
        x, y: [2]int
}

type T = struct {
        ws: weak ^S
}

fn main() {
        s := &S{{5, 7}, {9, 11}}
        t := T{s}
        t.ws = null
        a := t.ws.x
        printf("%v\n", a) // [0 0]
}