All includes handled relative to the main file #443

Open
opened 2022-12-16 16:11:36 +09:00 by davidyuk · 2 comments
davidyuk commented 2022-12-16 16:11:36 +09:00 (Migrated from gitlab.com)

As I see, include in included files only works relative to the main contract file. This is ok if we have all files in the same project, but if we include a contract from another repository or an npm package and that contract includes something relative to it then it won't work. I think the best is to resolve includes relative to the current file.

Reproduction

├── Includes.aes
└── lib
    ├── Library.aes
    └── Sublibrary.aes

Includes.aes

include "./lib/Library.aes"

contract Includes =
    entrypoint test(x: int): int = Library.sum(x, 4)

Library.aes

include "./Sublibrary.aes"

namespace Library =
  function sum(x: int, y: int) : int = Sublibrary.sum(x, y)

Sublibrary.aes

namespace Sublibrary =
  function sum(x: int, y: int) : int = x + y
$ aesophia_cli --version     
Sophia compiler version 7.0.1
$ aesophia_cli ./Includes.aes
Parse error in './lib/Library.aes' at line 1, col 1:
Couldn't find include file './Sublibrary.aes'

But if I replace

-include "./Sublibrary.aes"
+include "./lib/Sublibrary.aes"

in Library.aes then it works

As I see, `include` in included files only works relative to the main contract file. This is ok if we have all files in the same project, but if we include a contract from another repository or an npm package and that contract includes something relative to it then it won't work. I think the best is to resolve includes relative to the current file. ## Reproduction ``` ├── Includes.aes └── lib ├── Library.aes └── Sublibrary.aes ``` Includes.aes ``` include "./lib/Library.aes" contract Includes = entrypoint test(x: int): int = Library.sum(x, 4) ``` Library.aes ``` include "./Sublibrary.aes" namespace Library = function sum(x: int, y: int) : int = Sublibrary.sum(x, y) ``` Sublibrary.aes ``` namespace Sublibrary = function sum(x: int, y: int) : int = x + y ``` ```bash $ aesophia_cli --version Sophia compiler version 7.0.1 $ aesophia_cli ./Includes.aes Parse error in './lib/Library.aes' at line 1, col 1: Couldn't find include file './Sublibrary.aes' ``` But if I replace ```diff -include "./Sublibrary.aes" +include "./lib/Sublibrary.aes" ``` in Library.aes then it works
ghallak commented 2023-03-22 18:56:53 +09:00 (Migrated from gitlab.com)

The compiler should search for paths relative to the file that has the include at first, and then relative to the path of the main contract. That's how the erlang compiler seems to handle includes.

So I think that both include "./Sublibrary.aes" and include "./lib/Sublibrary.aes" should work.

The compiler should search for paths relative to the file that has the `include` at first, and then relative to the path of the main contract. That's how the erlang compiler seems to handle includes. So I think that both `include "./Sublibrary.aes"` and `include "./lib/Sublibrary.aes"` should work.
Owner

What is the status of this? I have issues with includes and was going to open a new bug report. If this is a known issue we should collect all info in one place

What is the status of this? I have issues with includes and was going to open a new bug report. If this is a known issue we should collect all info in one place
Sign in to join this conversation.
No Milestone
No project
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: QPQ-AG/sophia#443
No description provided.