githwxi / ATS-Postiats

ATS2: Unleashing the Potentials of Types and Templates
www.ats-lang.org
Other
354 stars 54 forks source link

Passing an array by reference does not work in a conditional expression #229

Closed rightfold closed 5 years ago

rightfold commented 5 years ago

When I compile the following program everything is fine:

extern fun foo{n: nat}(xs: &(@[string][n])): void = "ext#foo"
implement main0 () =
    let
        var xs = @[string]("foo", "bar")
        val () = foo(xs)
    in
        ()
    end

But when I compile this program, I get an error:

extern fun foo{n: nat}(xs: &(@[string][n])): void = "ext#foo"
implement main0 () =
    let
        var xs = @[string]("foo", "bar")
        val () = if true then foo(xs) else ()
    in
        ()
    end
/tmp/871893664/main.dats: 176(line=5, offs=44) -- 178(line=5, offs=46): error(3): mismatch of static terms (tyleq):
The actual term is: S2Ecst(string_type)
The needed term is: S2Ecst(ptr_type)

The only difference between the two programs is if true then ... else () around the call foo(xs).

I'm not sure what is causing this but it seems like a bug to be; the presence of a conditional expression shouldn't influence the type of xs.

This problem does not occur when foo takes the array by value. The problem also occurs when using array_v.

I'm using ATS/Postiats version 0.3.11.

githwxi commented 5 years ago

The typechecker could not figure out the so-called master type of 'xs'; it picked @[string?][2] by default.

You can specify it as follows:

var xs: @[string][2] = @string

On Tue, Jan 8, 2019 at 6:14 PM rightfold notifications@github.com wrote:

When I compile the following program everything is fine:

extern fun foo{n: nat}(xs: &(@[string][n])): void = "ext#foo"implement main0 () = let var xs = @string val () = foo(xs) in () end

But when I compile this program, I get an error:

extern fun foo{n: nat}(xs: &(@[string][n])): void = "ext#foo"implement main0 () = let var xs = @string val () = if true then foo(xs) else () in () end

/tmp/871893664/main.dats: 176(line=5, offs=44) -- 178(line=5, offs=46): error(3): mismatch of static terms (tyleq): The actual term is: S2Ecst(string_type) The needed term is: S2Ecst(ptr_type)

I'm not sure what is causing this but it seems like a bug to be; the presence of a conditional expression shouldn't influence the type of xs.

This problem does not occur when foo takes the array by value. The problem also occurs when using array_v.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/githwxi/ATS-Postiats/issues/229, or mute the thread https://github.com/notifications/unsubscribe-auth/AAl81z9EPIoXtwDuH7T-x8jpaiZ6B3N6ks5vBSZagaJpZM4Z2dIe .

rightfold commented 5 years ago

Thank you, that did the trick.