external_functions.sol 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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) public 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: 25:16-27: functions declared external cannot be called via an internal function call
  35. // note 19:5-61: declaration of function 'hello'
  36. // error: 30:16-35: functions declared external cannot be called via an internal function call
  37. // note 19:5-61: declaration of function 'hello'
  38. // 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
  39. // error: 40:16-38: functions declared external cannot be called via an internal function call
  40. // note 10:5-72: declaration of function 'this_is_external'