Skip to content

Commit

Permalink
Bug is avoided by not upcasting to same type. Bug still exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpressey committed Feb 17, 2022
1 parent e0437b5 commit f471be3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ TODO
call equal_tagged_value() when you find a union type when
comparing structs deeply. (C backend, probably others)

There appears to be a bug with casting a union type to
itself? The tag in the tagged value is the union?

Name mangling for compilers (prepend with `_` most likely.)

And literal characters in strings, especially `'` and `"`.
Expand Down
2 changes: 1 addition & 1 deletion eg/assoc.castile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fun lookup(a: assoc, k: string) {
return null as string|void
}
typecase n is assoc {
return lookup(n, k) as string|void
return lookup(n, k)
}
}

Expand Down
23 changes: 22 additions & 1 deletion tests/Castile.md
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,27 @@ Deeply nested structs can be tested for equality.
| }
= True

Deeply nested structs can be tested for equality, even when containing values
of union type.

| struct name { first: string; last: string|integer }
| struct person { age: integer; name: name }
| main = fun() {
| j = make person(age: 23, name:make name(first:"Bamber", last:"Smith" as string|integer));
| k = make person(age: 23, name:make name(first:"Bamber", last:"Smith" as string|integer));
| j == k
| }
= True

| struct name { first: string; last: string|integer }
| struct person { age: integer; name: name }
| main = fun() {
| j = make person(age: 23, name:make name(first:"Bamber", last:"Smith" as string|integer));
| k = make person(age: 23, name:make name(first:"Bamber", last:75 as string|integer));
| j != k
| }
= True

Structs cannot be compared for ordering.

| struct person { age: integer; name: string }
Expand Down Expand Up @@ -1354,7 +1375,7 @@ One can use this facility to implement abstract data types.
| return null as string|void
| }
| typecase n is assoc {
| return lookup(n, k) as string|void
| return lookup(n, k)
| }
| }
|
Expand Down

0 comments on commit f471be3

Please sign in to comment.