Add missing type check of init function

This commit is contained in:
Ulf Norell
2019-01-08 12:27:39 +01:00
parent 5786b6d813
commit 7849fe302c
4 changed files with 40 additions and 2 deletions
+10 -2
View File
@@ -21,8 +21,8 @@ simple_compile_test_() ->
fun (_) -> ok end, %Cleanup
[ {"Testing the " ++ ContractName ++ " contract",
fun() ->
#{byte_code := ByteCode,
contract_source := _,
#{byte_code := ByteCode,
contract_source := _,
type_info := _} = compile(ContractName),
?assertMatch(Code when is_binary(Code), ByteCode)
end} || ContractName <- compilable_contracts() ] ++
@@ -133,4 +133,12 @@ failing_contracts() ->
"Repeated name x in pattern\n"
" x :: x (at line 26, column 7)\n",
"No record type with fields y, z (at line 14, column 22)\n"]}
, {"init_type_error",
["Cannot unify string\n"
" and map(int, int)\n"
"when checking that 'init' returns a value of type 'state' at line 7, column 3\n"]}
, {"missing_state_type",
["Cannot unify string\n"
" and ()\n"
"when checking that 'init' returns a value of type 'state' at line 5, column 3\n"]}
].
+8
View File
@@ -0,0 +1,8 @@
contract InitTypeError =
type state = map(int, int)
// Check that the compiler catches ill-typed init function
function init() = "not the right type!"
+6
View File
@@ -0,0 +1,6 @@
contract MissingStateType =
// Check that we get a type error also for implicit state
function init() = "should be ()"