external_functions.sol 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. function doThis(address id) returns (int) {
  2. // This is allwoed
  3. return bar1.this_is_external{program_id: id}(1, 2);
  4. }
  5. contract bar1 {
  6. constructor() {}
  7. function this_is_external(int a, int b) external pure returns (int) {
  8. return a-b;
  9. }
  10. }
  11. contract bar2 is bar1 {
  12. constructor() {}
  13. function hello(int a, int b) external pure returns (int) {
  14. return a - b;
  15. }
  16. function test2(int c, int d) external returns (int) {
  17. // Not allowed
  18. return hello(c, d);
  19. }
  20. function test3(int f, int g) external returns (int) {
  21. // Not allowed
  22. return hello({b: g, a: f});
  23. }
  24. function test4(int c, int d) external returns (int) {
  25. // This is allowed
  26. return this.this_is_external(c, d) + this.hello(d, c);
  27. }
  28. function test5(int f, int g) external returns (int) {
  29. // Not allowed
  30. return this_is_external(f, g);
  31. }
  32. }
  33. // ---- Expect: diagnostics ----
  34. // error: 4:12-55: accounts are required for calling a contract. You can either provide the accounts with the {accounts: ...} call argument or change this function's visibility to external
  35. // error: 25:16-27: functions declared external cannot be called via an internal function call
  36. // note 19:5-61: declaration of function 'hello'
  37. // error: 30:16-35: functions declared external cannot be called via an internal function call
  38. // note 19:5-61: declaration of function 'hello'
  39. // error: 35:16-43: a contract needs a program id to be called. Either a '@program_id' must be declared above a contract or the {program_id: ...} call argument must be present
  40. // error: 40:16-38: functions declared external cannot be called via an internal function call
  41. // note 10:5-72: declaration of function 'this_is_external'