Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All includes handled relative to the main file #443

Open
davidyuk opened this issue Dec 16, 2022 · 1 comment
Open

All includes handled relative to the main file #443

davidyuk opened this issue Dec 16, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@davidyuk
Copy link
Member

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

@ghallak ghallak transferred this issue from aeternity/aesophia_cli Mar 22, 2023
@ghallak
Copy link
Contributor

ghallak commented Mar 22, 2023

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.

@ghallak ghallak self-assigned this Mar 22, 2023
@ghallak ghallak added the enhancement New feature or request label Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants