Lifting redundant constructor restrictions
-
Review changes -
-
Download -
Patches
-
Plain diff
type:changed
problems
-
tv_opt
was almost ignored in the typing of E_constructor (if not to substitute the free variables in the type of constructor parameter) -
evaluate_type
was weird ? it seems to me that we should look-up the context in the E_app and E_var cases, and add to the context in the T_for_all T_abstraction cases ?
the redundant constructor problem (we could not write that)
type union_a =
| Add of int
| Remove of int
type union_b =
| Add of nat
| Config of nat
let x = (Add 1 : union_a) , (Add 1n : union_b)
Although we could write this ! but it was wrong:
type t1 =
| B of nat
| C of int
| D of string
| A of unit
type t2 =
[@layout:comb]
| B of nat
| C of int
| D of string
| A of unit
let x = (B 42n : t1) , (B 42n : t2)
> ../ligo.37.0 compile expression cameligo "x" --ini result/oueach.mligo
(Pair (Left (Right 42)) (Left (Right 42)))
> ligo compile expression cameligo "x" --ini result/oueach.mligo
(Pair (Left (Right 42)) (Left 42))
Semantic: The most recently declared constructor is chosen by default (this is more or less OCaml behavior). A warning will pop if two constructor with the same label and same parameter type are in scope:
type union_a =
| A of int
| B of int
type union_b =
| A of int
| B of nat
(* here we expect a warning because both A constructor have the same parameter type *)
let main = fun (() , (_: union_b)) -> ([]: operation list) , A 1
File "test.mligo", line 10, characters 61-66:
9 |
10 | let main = fun (() , (_: union_b)) -> ([]: operation list) , Add 1
The type of this value is ambiguous: Inferred type is union_b but could be of type union_a.
Hint: You might want to add a type annotation.
Changelog details:
Lifting restrictions on redundant constructors
It is now possible to declare variant types sharing the same constructors as in:
type t1 =
| Foo of int
| Bar of string
type t2 =
| Foo of int
| Baz of nat
Edited by Laurent Canis
Merge request reports
Compare and
Show latest version
- version 17c9f01e93
- version 16d8d1a2d9
- version 159e0404d2
- version 14f8608706
- version 13beffbecd
- version 1264a82137
- version 116ffccb36
- version 10bf6cab5f
- version 958f21283
- version 827331620
- version 7e4bfa5c6
- version 68bc5b5f3
- version 53be3e07e
- version 4dabf2157
- version 33f4bf9d0
- version 2acd6f71f
- version 1acd6f71f
- dev (base)
- latest version8985e94220 commits,
- version 17c9f01e9320 commits,
- version 16d8d1a2d919 commits,
- version 159e0404d218 commits,
- version 14f860870617 commits,
- version 13beffbecd15 commits,
- version 1264a8213714 commits,
- version 116ffccb3612 commits,
- version 10bf6cab5f11 commits,
- version 958f2128310 commits,
- version 8273316209 commits,
- version 7e4bfa5c68 commits,
- version 68bc5b5f36 commits,
- version 53be3e07e3 commits,
- version 4dabf21572 commits,
- version 33f4bf9d01 commit,
- version 2acd6f71f2 commits,
- version 1acd6f71f6 commits,
Compare changes
- Side-by-side
- Inline
Files
8Loading