oridb / mc

Myrddin Compiler
MIT License
387 stars 34 forks source link

Pattern-matching a value causes Infinite loops #183

Closed typeless closed 4 years ago

typeless commented 6 years ago
use std

type ty = union
        `Tyarray int
        `Other
;;

type srcloc = struct
        file    : byte[:]
        line    : int
;;

type tydef = struct
        ty      : ty
        loc     : srcloc
        fixed   : bool
;;

const istyarray = {t
        match t
        | [.ty=`Tyarray 1 ]:    -> true
        | _:                    -> false
        ;;
}

const main = {
        var b : tydef = [.ty = `Other]
        var v = istyarray(b)

        std.put("{}\n", v)
}

Tested with the master (9664143) I expected that it should show 'false'. It's not obvious how this could generate an infinite loop. Not an urgent issue.

oridb commented 6 years ago

That's definitely an issue. Thanks, will look into it in the next little while. This is definitely a miscompilation, so it's a pretty high priority issue. The code generated for the wildcard branch of the match is:

        #/home/ori/src/myr/mc/infloop.myr:22
        .loc 1 22
    .L11:
    .L9:
    .L12:
        jmp .L9
oridb commented 6 years ago

I'm probably going to take the time to actually clean up mi/match.c while I do this, so this may take a bit of time to fix. I'll see if I can put in a quick fix in the mean time.

typeless commented 6 years ago

No problem. Take your time.