You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let {List} = import! "std/list.glu"
type R = { a: String, b: Int }
let f r n : R -> Int -> R =
{b=n, ..r}
let r = {a="hello", b=1}
let r2 = f r 2
r2.b
The order of members of R has been changed, so that where we had {a: String, b: Int} we now have {b: Int, a: String}, and these two types are, apparently, not equal.
<top>:Line: 6, Column: 3: Expected the following types to be equal
Expected: <top>.R
Found: { b : Int, a : String }
2 errors were found during unification:
Field names in record do not match.
Expected: a
Found: b
Field names in record do not match.
Expected: b
Found: a
{b=n, ..r}
^~~~~~~~~~
This makes it difficult to create functions which update and return specific fields in complex structs/records.
The text was updated successfully, but these errors were encountered:
I think this case may be solvable by taking the type of ..r into account first, before appending and replacing the other fields. That way field order of r is preserved making the behavior less surprising.
More generally we might want to accept code like this.
typeR={ a:String, b: Int }letr:R ={b=1, a="hello"}
r
where the field order is "wrongly" specified. I think the only way to solve that is to have a deterministic field order for records (can be done by sorting the fields lexically).
Marwes
added a commit
to Marwes/gluon
that referenced
this issue
Sep 23, 2018
The following code illustrates the bug (This will run in http://gluon-lang.org/try/)
The order of members of R has been changed, so that where we had
{a: String, b: Int}
we now have{b: Int, a: String}
, and these two types are, apparently, not equal.This makes it difficult to create functions which update and return specific fields in complex structs/records.
The text was updated successfully, but these errors were encountered: