flix / flix

The Flix Programming Language
https://flix.dev/
Other
2.15k stars 151 forks source link

faulty unification of datalog programs and return types #4506

Closed JonathanStarup closed 9 months ago

JonathanStarup commented 2 years ago

I am a bit unsure in which system this error lives, but there are two issues with returning datalog values (and ascriptions).

1) underspecified types are sometimes accepted (distinctPairs do not mention Pair in its type, omiting Fact is not allowed). This also applies to ascriptions.

pub def bug(): List[(Int32, Int32)] =
    query #{Fact(1). Fact(2).} <+> distinctPairs()
    select (x, y) from Pair(x, y)

def distinctPairs(): #{Fact(Int32) | r} =
    #{Pair(x: Int32, y: Int32) :- Fact(x), Fact(y), if x != y.}

2) Incorrect type class handling (This results in an empty list instead of (1,2)::(2,1)::Nil because the condition is always false. The asciption of x or y to Int32 fixes this as shown above)

pub def bug(): List[(Int32, Int32)] =
    query #{Fact(1). Fact(2).} <+> distinctPairs()
    select (x, y) from Pair(x, y)

def distinctPairs(): #{Pair(Int32, Int32), Fact(Int32) | r} =
    #{Pair(x, y) :- Fact(x), Fact(y), if x != y.}
JonathanStarup commented 1 year ago

From @paulbutcher (this compiles)

def foo(): #{ Thingy(String) | s } = #{
    Widget("x").
}
magnus-madsen commented 9 months ago

Fixed in master.