oridb / mc

Myrddin Compiler
MIT License
389 stars 33 forks source link

std.put printing incorrect values for nested structs #88

Closed andrewchambers closed 8 years ago

andrewchambers commented 8 years ago

bug.myr

use std

type qid = struct
    ty  : uint8
    vers    : uint32
    path    : uint64
;;

type stat = struct
// Commenting out ty fixes the issue.
    ty  : uint16
    qid : qid
;;

const main = {
    var s : stat# = std.mk([
            .qid=[.path=1, .ty=0x8, .vers=0],
            .ty=0,
    ])
    std.put("stat={}\n", s#)
    std.put("stat.qid={}\n", s#.qid)
}
ac@nomad:~/Desktop/bug$ mbld -b bug bug.myr && ./bug
bug...
stat=[.ty=0, .qid=[.ty=65, .vers=0, .path=4307720]]
stat.qid=[.ty=8, .vers=0, .path=1]
andrewchambers commented 8 years ago

More minimal example:

use std

pkg = 
    type msg = union
        `Tversion   tversion
    ;;
    type tversion = struct
        tag : uint16
        version : byte[:]
    ;;
;;

const main = {
    var msg=`Tversion [.tag=45, .version="9P2000"]
    std.put("msg={}\n", msg)
}

gives a segfault on my machine.