Add test for accessing maps with the wrong type

This commit is contained in:
Gaith Hallak 2022-05-25 18:35:13 +04:00
parent 0c8b95c16d
commit 8d419bc54f
2 changed files with 17 additions and 2 deletions

View File

@ -876,9 +876,12 @@ failing_contracts() ->
" `g5 : ((Animal) => Animal) => Cat`\n" " `g5 : ((Animal) => Animal) => Cat`\n"
"to arguments\n" "to arguments\n"
" `x : (Cat) => Cat`">>, " `x : (Cat) => Cat`">>,
<<?Pos(52, 44) <<?Pos(52,44)
"Cannot unify `Animal` and `Cat` in a covariant context\n" "Cannot unify `Animal` and `Cat` in a covariant context\n"
"when checking the type of the expression `f6() : option(Animal)` against the expected type `option(Cat)`">> "when checking the type of the expression `f6() : option(Animal)` against the expected type `option(Cat)`">>,
<<?Pos(73,43)
"Cannot unify `Animal` and `Cat` in a covariant context\n"
"when checking the type of the expression `some_animal : Animal` against the expected type `Cat`">>
]) ])
, ?TYPE_ERROR(polymorphism_variance_switching_custom_types, , ?TYPE_ERROR(polymorphism_variance_switching_custom_types,
[<<?Pos(56,39) [<<?Pos(56,39)

View File

@ -61,3 +61,15 @@ main contract Main =
stateful function g72() : cat_cat_map = { [Chain.create()] = Chain.create() } stateful function g72() : cat_cat_map = { [Chain.create()] = Chain.create() }
stateful function f72() : animal_animal_map = g13() stateful function f72() : animal_animal_map = g13()
stateful function g73() =
let some_cat : Cat = Chain.create()
let some_animal : Animal = some_cat
let some_cat_cat_map : map(Cat, Cat) = g13()
let some_animal_animal_map : map(Animal, Animal) = some_cat_cat_map
let x : Animal = some_animal_animal_map[some_cat] // success
let y : Cat = some_cat_cat_map[some_animal] // fail
()