From 53abda625a16b18493c09941758ebd87ec5bf00c Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Wed, 3 Aug 2022 18:55:51 +0400 Subject: [PATCH 1/5] Get the type of Chain.create() from its application --- src/aeso_ast_to_fcode.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aeso_ast_to_fcode.erl b/src/aeso_ast_to_fcode.erl index a4f7ce6..1cb00fe 100644 --- a/src/aeso_ast_to_fcode.erl +++ b/src/aeso_ast_to_fcode.erl @@ -693,7 +693,7 @@ expr_to_fcode(Env, _Type, {app, _Ann, {Op, _}, [A]}) when is_atom(Op) -> end; %% Function calls -expr_to_fcode(Env, Type, {app, _, Fun = {typed, _, FunE, {fun_t, _, NamedArgsT, ArgsT, _}}, Args}) -> +expr_to_fcode(Env, _, {app, _, Fun = {typed, _, FunE, {fun_t, _, NamedArgsT, ArgsT, Type}}, Args}) -> Args1 = get_named_args(NamedArgsT, Args), FArgs = [expr_to_fcode(Env, Arg) || Arg <- Args1], case expr_to_fcode(Env, Fun) of -- 2.30.2 From e3c82e954db010803a843d4a88db69577d739173 Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Wed, 3 Aug 2022 18:59:50 +0400 Subject: [PATCH 2/5] Add test contract --- test/aeso_compiler_tests.erl | 1 + test/contracts/polymorphism_chain_create.aes | 23 ++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/contracts/polymorphism_chain_create.aes diff --git a/test/aeso_compiler_tests.erl b/test/aeso_compiler_tests.erl index a10c885..d2fb5b6 100644 --- a/test/aeso_compiler_tests.erl +++ b/test/aeso_compiler_tests.erl @@ -202,6 +202,7 @@ compilable_contracts() -> "polymorphism_contract_interface_extensions", "polymorphism_contract_interface_same_decl_multi_interface", "polymorphism_contract_interface_same_name_same_type", + "polymorphism_chain_create", "missing_init_fun_state_unit", "complex_compare_leq", "complex_compare", diff --git a/test/contracts/polymorphism_chain_create.aes b/test/contracts/polymorphism_chain_create.aes new file mode 100644 index 0000000..78fe9c8 --- /dev/null +++ b/test/contracts/polymorphism_chain_create.aes @@ -0,0 +1,23 @@ +contract interface I = + entrypoint f : () => int + +contract C1 : I = + entrypoint f() = 123 + +contract C2 : I = + entrypoint f() = 888 + +namespace Make = + stateful function new1() : I = Chain.create() : C1 + stateful function new2() : I = Chain.create() : C2 + + stateful function new(c : I) : int = c.f() + +main contract Main = + stateful entrypoint test1() = + let c = Make.new1() + Make.new(c) + + stateful entrypoint test2() = + let c = Make.new2() + Make.new(c) -- 2.30.2 From 51a6b704fa6cc6f0a3820582dec09b918972093e Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Wed, 3 Aug 2022 19:01:46 +0400 Subject: [PATCH 3/5] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb15d90..dca4e56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed ### Removed +### Fixed +- [404](https://github.com/aeternity/aesophia/issues/404) Contract polymorphism crashes on non-obvious child contract typing. ## [7.0.0] ### Added -- 2.30.2 From a87eb36778900f087105ad553325f12aca35b0d8 Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Wed, 3 Aug 2022 19:59:12 +0400 Subject: [PATCH 4/5] Update the tests --- test/aeso_compiler_tests.erl | 15 ++++++++++++++- ...ymorphism_variance_switching_chain_create.aes} | 9 +++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) rename test/contracts/{polymorphism_chain_create.aes => polymorphism_variance_switching_chain_create.aes} (57%) diff --git a/test/aeso_compiler_tests.erl b/test/aeso_compiler_tests.erl index d2fb5b6..ad45982 100644 --- a/test/aeso_compiler_tests.erl +++ b/test/aeso_compiler_tests.erl @@ -202,7 +202,6 @@ compilable_contracts() -> "polymorphism_contract_interface_extensions", "polymorphism_contract_interface_same_decl_multi_interface", "polymorphism_contract_interface_same_name_same_type", - "polymorphism_chain_create", "missing_init_fun_state_unit", "complex_compare_leq", "complex_compare", @@ -1026,6 +1025,20 @@ failing_contracts() -> "Cannot unify `Animal` and `Cat` in a covariant context\n" "when checking the type of the pattern `q15 : oracle_query(Cat, Cat)` against the expected type `oracle_query(Cat, Animal)`">> ]) + , ?TYPE_ERROR(polymorphism_variance_switching_chain_create, + [<>, + <>, + <>, + <> + ]) , ?TYPE_ERROR(missing_definition, [<> diff --git a/test/contracts/polymorphism_chain_create.aes b/test/contracts/polymorphism_variance_switching_chain_create.aes similarity index 57% rename from test/contracts/polymorphism_chain_create.aes rename to test/contracts/polymorphism_variance_switching_chain_create.aes index 78fe9c8..69c11c2 100644 --- a/test/contracts/polymorphism_chain_create.aes +++ b/test/contracts/polymorphism_variance_switching_chain_create.aes @@ -21,3 +21,12 @@ main contract Main = stateful entrypoint test2() = let c = Make.new2() Make.new(c) + + stateful entrypoint test3() = + let c1 : I = Chain.create() // fails + let c2 : C1 = Chain.create() : I // fails + let c3 = Chain.create() : I // fails + let c4 = Chain.create() : C1 // succeeds + let c5 : I = Chain.create() : C1 // succeeds + let c6 : C1 = Chain.create() // succeeds + () -- 2.30.2 From d4e5de732d8f56caca6da3f35af29acd8defeec9 Mon Sep 17 00:00:00 2001 From: Gaith Hallak Date: Wed, 3 Aug 2022 20:11:23 +0400 Subject: [PATCH 5/5] Update tests again --- test/aeso_compiler_tests.erl | 15 ++++++++------- ...lymorphism_variance_switching_chain_create.aes | 9 +++------ ...phism_variance_switching_chain_create_fail.aes | 12 ++++++++++++ 3 files changed, 23 insertions(+), 13 deletions(-) create mode 100644 test/contracts/polymorphism_variance_switching_chain_create_fail.aes diff --git a/test/aeso_compiler_tests.erl b/test/aeso_compiler_tests.erl index ad45982..57b25b4 100644 --- a/test/aeso_compiler_tests.erl +++ b/test/aeso_compiler_tests.erl @@ -202,6 +202,7 @@ compilable_contracts() -> "polymorphism_contract_interface_extensions", "polymorphism_contract_interface_same_decl_multi_interface", "polymorphism_contract_interface_same_name_same_type", + "polymorphism_variance_switching_chain_create", "missing_init_fun_state_unit", "complex_compare_leq", "complex_compare", @@ -1025,17 +1026,17 @@ failing_contracts() -> "Cannot unify `Animal` and `Cat` in a covariant context\n" "when checking the type of the pattern `q15 : oracle_query(Cat, Cat)` against the expected type `oracle_query(Cat, Animal)`">> ]) - , ?TYPE_ERROR(polymorphism_variance_switching_chain_create, - [<>, - <>, - <>, + <>, - <> ]) diff --git a/test/contracts/polymorphism_variance_switching_chain_create.aes b/test/contracts/polymorphism_variance_switching_chain_create.aes index 69c11c2..14c5f0b 100644 --- a/test/contracts/polymorphism_variance_switching_chain_create.aes +++ b/test/contracts/polymorphism_variance_switching_chain_create.aes @@ -23,10 +23,7 @@ main contract Main = Make.new(c) stateful entrypoint test3() = - let c1 : I = Chain.create() // fails - let c2 : C1 = Chain.create() : I // fails - let c3 = Chain.create() : I // fails - let c4 = Chain.create() : C1 // succeeds - let c5 : I = Chain.create() : C1 // succeeds - let c6 : C1 = Chain.create() // succeeds + let c1 = Chain.create() : C1 // succeeds + let c2 : I = Chain.create() : C1 // succeeds + let c3 : C1 = Chain.create() // succeeds () diff --git a/test/contracts/polymorphism_variance_switching_chain_create_fail.aes b/test/contracts/polymorphism_variance_switching_chain_create_fail.aes new file mode 100644 index 0000000..836c9e1 --- /dev/null +++ b/test/contracts/polymorphism_variance_switching_chain_create_fail.aes @@ -0,0 +1,12 @@ +contract interface I = + entrypoint f : () => int + +contract C : I = + entrypoint f() = 123 + +main contract Main = + stateful entrypoint test() = + let c1 : I = Chain.create() // fails + let c2 : C = Chain.create() : I // fails + let c3 = Chain.create() : I // fails + () \ No newline at end of file -- 2.30.2