[CameLIGO] Fix type variable binding in expressions
Motivation and Context
There was a bug when there were type variable bindings in both LHS & RHS,
e.g. For
let foo (type a) : a list -> a list =
fun (type b) (xs : b list) : b list -> xs
The abstraction was
const foo : ∀ a : * . list (a) -> list (a) =
Λ a -> fun ( xs : list (b)) : list (b) -> xs
There was no type abstraction for b
Fixes #1669 (closed)
Description
This MR fixes the issue
const foo : ∀ a : * . list (a) -> list (a) =
Λ a -> Λ b -> fun ( xs : list (b)) : list (b) -> xs
Types of changes
-
Bug fix (non-breaking change which fixes an issue) -
New feature (non-breaking change which adds functionality) -
Breaking change (fix or feature that would cause existing functionality to not work as expected) -
Performance improvement (non-breaking change that improves performance) -
None (change with no changelog)
Changelog
For a cameligo file like
let foo (type a) : a list -> a list =
let id = fun (type b) (xs : b list) : b list -> xs in
fun (xs : a list) : a list -> id xs
let main (_ : unit * int list) : operation list * int list =
[], foo [1 ; 2 ; 3]
Before
$ ligo.60 compile contract x.mligo
File "x.mligo", line 2, characters 31-32:
1 | let foo (type a) : a list -> a list =
2 | let id = fun (type b) (xs : b list) : b list -> xs in
3 | fun (xs : a list) : a list -> id xs
Type "b" not found.
After
$ ligo compile contract x.mligo
{ parameter unit ;
storage (list int) ;
code { DROP ;
NIL int ;
PUSH int 3 ;
CONS ;
PUSH int 2 ;
CONS ;
PUSH int 1 ;
CONS ;
NIL operation ;
PAIR } }
Checklist:
-
Changes follow the existing coding style (use dune @fmt
to check). -
Tests for the changes have been added (for bug fixes / feature). -
Documentation has been updated. -
Changelog description has been added (if appropriate). -
Start titles under ## Changelog
section with #### (if appropriate). -
There is no image or uploaded file in changelog -
Examples in changed behaviour have been added to the changelog (for breaking change / feature).
Edited by Melwyn Saldanha