circular_reference.sol 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. contract Foo {
  2. uint b;
  3. function get_b(address id) external returns (uint) {
  4. Other.new{program_id: id}();
  5. return b;
  6. }
  7. }
  8. contract Other {
  9. function call_foo(address id) external {
  10. Foo.new{program_id: id}();
  11. }
  12. }
  13. contract Foo2 {
  14. uint b;
  15. constructor(uint a) {
  16. b = a;
  17. }
  18. function get_b(address id) external returns (uint) {
  19. Other2.new{program_id: id}(2);
  20. return b;
  21. }
  22. function get_b2(address id) external returns (uint) {
  23. Other2.new{program_id: id}({d: 2});
  24. return b;
  25. }
  26. }
  27. contract Other2 {
  28. uint c;
  29. constructor(uint d) {
  30. c = d;
  31. }
  32. function call_foo(address id) external {
  33. Foo2.new{program_id: id}(5);
  34. }
  35. function call_foo2(address id) external {
  36. Foo2.new{program_id: id}({a: 5});
  37. }
  38. }
  39. // ---- Expect: diagnostics ----
  40. // error: 11:9-34: circular reference creating contract 'Foo'
  41. // error: 38:9-36: circular reference creating contract 'Foo2'
  42. // error: 41:9-41: circular reference creating contract 'Foo2'