aeternity / aesophia

Stand alone compiler for the Sophia smart contract language
https://docs.aeternity.com/aesophia
ISC License
52 stars 19 forks source link

Sub-optimal include directory resolution #488

Closed hanssv closed 1 year ago

hanssv commented 1 year ago

Not sure if it is a minimal reproducing example, but it should be small enough. Three files, in three different directories: /tmp/foo.aes:

include "/tmp/dir1/bar.aes"
contract C =
  entrypoint f() = D.g()

/tmp/dir1/bar.aes:

include "../dir2/baz.aes"
namespace D =
  function g() = E.h()

/tmp/dir2/baz.aes:

namespace E =
  function h() = 42

Straight up compiling foo.aes fails:

Parse error in '/tmp/dir1/bar.aes' at line 1, col 1:
Couldn't find include file '../dir2/baz.aes'

The problem is that while resolving the includes in bar.aes (which is in dir1) we still do this relative to the root source file (i.e. in /tmp) this means we won't find ../dir2.

A workaround is to pass both the top level and the subdirectory as include paths:

$ ./aesophia_cli /tmp/foo.aes -i /tmp -i /tmp/dir2
cb_+JdGA6DSagnFZzPzngQuBCq056yYPk6ObA8ElyhfEBqi/J/jPMC4arg9/gbU40wCNwAHAQNU/kTWRB8ANwA3ABoOgj8BAz/+eCFrswI3AAcEAxEG1ONM/uC+/GEANwAHBAMReCFrs6cvBBEG1ONMES5FLmgRRNZEHxFpbml0EXgha7MRLkQuZxHgvvxhBWaCLwCFNy40LjAA3jUBlw==
marc0olo commented 1 year ago

thanks for creating the issue! 👍

maybe it would be good if the include path doesn't have to be referenced at all if every path is relative? 🤔

hanssv commented 1 year ago

Definitely - this contract should compile with aesophia_cli /tmp/foo.aes and nothing more.

radrow commented 1 year ago

Module system in Sophia is inherently broken and we plan to fix it in the rewritten version. I am giving it low priority because

hanssv commented 1 year ago

Straighforward to fix for now 😅