Add tests for variance switching

This commit is contained in:
Gaith Hallak 2021-12-29 15:24:52 +02:00
parent 4348affa3e
commit e5e7958c3f
2 changed files with 64 additions and 0 deletions

View File

@ -868,6 +868,20 @@ failing_contracts() ->
[<<?Pos(1,24) [<<?Pos(1,24)
"Trying to implement or extend an undefined interface H at line 1, column 24">> "Trying to implement or extend an undefined interface H at line 1, column 24">>
]) ])
, ?TYPE_ERROR(polymorphism_variance_switching,
[<<?Pos(38,49)
"Cannot unify Animal\n"
" and Cat\n"
"when checking the application at line 38, column 49 of\n g2 : (Cat) => Cat\nto arguments\n x : Animal">>,
<<?Pos(41,43)
"Cannot unify Animal\n"
" and Cat\n"
"when checking the type of the expression at line 41, column 43\n g3(x) : Animal\nagainst the expected type\n Cat">>,
<<?Pos(50,55)
"Cannot unify Animal\n"
" and Cat\n"
"when checking the application at line 50, column 55 of\n g5 : ((Animal) => Animal) => Cat\nto arguments\n x : (Cat) => Cat">>
])
]. ].
-define(Path(File), "code_errors/" ??File). -define(Path(File), "code_errors/" ??File).

View File

@ -0,0 +1,50 @@
contract interface Creature =
entrypoint is_alive : () => bool
contract interface Animal : Creature =
entrypoint sound : () => string
contract Cat : Animal =
entrypoint sound() = "meow"
entrypoint is_alive() = true
main contract Main =
entrypoint init() = ()
stateful function g0(x : Creature) : Cat = Chain.create()
stateful function f0(x : Cat) : Creature = g1(x)
stateful function h0() =
let a : Animal = (Chain.create() : Cat)
let c : Creature = (Chain.create() : Cat)
let c1 : Creature = a
()
stateful function g1(x : Animal) : Cat = Chain.create()
stateful function f1(x : Cat) : Animal = g1(x)
stateful function h1() =
let x : Animal = (Chain.create() : Cat)
()
stateful function g11(x : list(Animal)) : list(Cat) = [Chain.create()]
stateful function f11(x : list(Cat)) : list(Animal) = g11(x)
stateful function g12(x : Animal * Animal) : Cat * Cat = (Chain.create(), Chain.create())
stateful function f12(x : Cat * Cat) : Animal * Animal = g12(x)
stateful function g13() : map(Cat, Cat) = { [Chain.create()] = Chain.create() }
stateful function f13() : map(Animal, Animal) = g13()
stateful function g2(x : Cat) : Cat = Chain.create()
stateful function f2(x : Animal) : Animal = g2(x)
stateful function g3(x : Cat) : Animal = f1(x)
stateful function f3(x : Cat) : Cat = g3(x)
stateful function g4(x : (Cat => Animal)) : Cat = Chain.create()
stateful function f4(x : (Animal => Cat)) : Animal = g4(x)
stateful function g44(x : list(list(Cat) => list(Animal))) : Cat = Chain.create()
stateful function f44(x : list(list(Animal) => list(Cat))) : Animal = g44(x)
stateful function g5(x : (Animal => Animal)) : Cat = Chain.create()
stateful function f5(x : (Cat => Cat)) : Animal = g5(x)