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

Make import_no Optional #1443

Closed

Conversation

BenTheKush
Copy link
Contributor

@BenTheKush BenTheKush commented Jul 14, 2023

This PR does 2 things:

  1. Makes ResolvedFile::import_no an Option<usize>
  2. Improves test suite for import logic

This is a first attempt, I imagine there are a few things that can be improved.

Possible issues include:

  1. Some import_nos are set to 0 when no import is used per this conversation; in this case, the import_no should be set to None. However, I imagine others are set to 0 because it is the first import that is performed. I currently just changed all literal import_no: 0 to import_no: Some(0) to get it to type check, but I'm guessing they may actually want to be import_no: None.
  2. @seanyoung you wanted more tests, and in particular for:
    1. when no import path is used, and
    2. "when a file is resolved via relative paths and not via import paths/maps".
      Could you expand on these more? For (i), how would I set up a case when no import path is used? For (ii), do you mean in an import statement (like import ./blah.sol)? I have a test that does this (imports integrations/polkadots/createpair.sol which has a relative import), but I'm not sure exactly what we want to test.

Comment on lines +648 to +649
&polkadot,
&cache.get_import_path(file.import_no.unwrap()).unwrap().1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing is imported via import path so these asserts should assert!(file.import_no.is_none());

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand, "createpair.sol" is resolved by file resolver by walking over import paths. If I don't add polkadot as an import path to the file resolver then tests fail.

Copy link
Contributor

@seanyoung seanyoung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i. when no import path is used, and

Yes, add a test which removes:

assert!(cache.add_import_path(polkadot.as_path()).is_ok());

ii. "when a file is resolved via relative paths and not via import paths/maps".
Could you expand on these more? For (i), how would I set up a case when no import path is used? For (ii), do you mean in an import statement (like import ./blah.sol)? I have a test that does this (imports integrations/polkadots/createpair.sol which has a relative import), but I'm not sure exactly what we want to test.

let path = OsStr::from("examples/polkadot/flipper.sol");
let ns = parse_and_resolve(path, &mut cache, Target::EVM);

@@ -206,7 +206,7 @@ impl FileResolver {
return Ok(ResolvedFile {
full_path,
base,
import_no: 0,
import_no: Some(0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None/copy of parent

@@ -218,12 +218,12 @@ impl FileResolver {
return Ok(ResolvedFile {
full_path,
base,
import_no: 0,
import_no: Some(0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy of parent import_no

@@ -236,7 +236,7 @@ impl FileResolver {
return Ok(ResolvedFile {
full_path,
base,
import_no: 0,
import_no: Some(0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy of import_no in cache

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where can I get this? I don't think this is accessible through FileResolver (it's in File which is stored in Namespace).

@bkushigian
Copy link

@seanyoung just wanted to follow up on this PR. I left a couple replies above.

seanyoung added a commit to seanyoung/solang that referenced this pull request Jul 27, 2023
When importing in Solidity, `import "foo";` does not check path relative to the currrent
file, only `import "./foo";` does.

This work is also a re-write of hyperledger-solang#1443

Signed-off-by: Sean Young <[email protected]>
seanyoung added a commit to seanyoung/solang that referenced this pull request Jul 27, 2023
When importing in Solidity, `import "foo";` does not check path relative to the currrent
file, only `import "./foo";` does.

This work is also a re-write of hyperledger-solang#1443

Signed-off-by: Sean Young <[email protected]>
seanyoung added a commit to seanyoung/solang that referenced this pull request Jul 27, 2023
When importing in Solidity, `import "foo";` does not check path relative to the currrent
file, only `import "./foo";` does.

This work is also a re-write of hyperledger-solang#1443

Signed-off-by: Sean Young <[email protected]>
@seanyoung
Copy link
Contributor

@seanyoung just wanted to follow up on this PR. I left a couple replies above.

I've looked at this and wrote a new PR #1465 which solves a number of issues including import_no being optional. Would you mind having a look and see if that works for you.

seanyoung added a commit to seanyoung/solang that referenced this pull request Jul 27, 2023
When importing in Solidity, `import "foo";` does not check path relative to the currrent
file, only `import "./foo";` does.

This work is also a re-write of hyperledger-solang#1443

Signed-off-by: Sean Young <[email protected]>
seanyoung added a commit to seanyoung/solang that referenced this pull request Jul 28, 2023
When importing in Solidity, `import "foo";` does not check path relative to the currrent
file, only `import "./foo";` does.

This work is also a re-write of hyperledger-solang#1443

Signed-off-by: Sean Young <[email protected]>
seanyoung added a commit to seanyoung/solang that referenced this pull request Jul 28, 2023
When importing in Solidity, `import "foo";` does not check path relative to the currrent
file, only `import "./foo";` does.

This work is also a re-write of hyperledger-solang#1443

Signed-off-by: Sean Young <[email protected]>
seanyoung added a commit to seanyoung/solang that referenced this pull request Jul 28, 2023
When importing in Solidity, `import "foo";` does not check path relative to the currrent
file, only `import "./foo";` does.

This work is also a re-write of hyperledger-solang#1443

Signed-off-by: Sean Young <[email protected]>
seanyoung added a commit to seanyoung/solang that referenced this pull request Aug 1, 2023
When importing in Solidity, `import "foo";` does not check path relative to the currrent
file, only `import "./foo";` does.

This work is also a re-write of hyperledger-solang#1443

Signed-off-by: Sean Young <[email protected]>
seanyoung added a commit to seanyoung/solang that referenced this pull request Aug 1, 2023
When importing in Solidity, `import "foo";` does not check path relative to the currrent
file, only `import "./foo";` does.

This work is also a re-write of hyperledger-solang#1443

Signed-off-by: Sean Young <[email protected]>
seanyoung added a commit to seanyoung/solang that referenced this pull request Aug 2, 2023
When importing in Solidity, `import "foo";` does not check path relative to the currrent
file, only `import "./foo";` does.

This work is also a re-write of hyperledger-solang#1443

Signed-off-by: Sean Young <[email protected]>
seanyoung added a commit to seanyoung/solang that referenced this pull request Aug 3, 2023
When importing in Solidity, `import "foo";` does not check path relative to the currrent
file, only `import "./foo";` does.

This work is also a re-write of hyperledger-solang#1443

Signed-off-by: Sean Young <[email protected]>
seanyoung added a commit to seanyoung/solang that referenced this pull request Aug 8, 2023
When importing in Solidity, `import "foo";` does not check path relative to the currrent
file, only `import "./foo";` does.

This work is also a re-write of hyperledger-solang#1443

Signed-off-by: Sean Young <[email protected]>
seanyoung added a commit to seanyoung/solang that referenced this pull request Aug 9, 2023
When importing in Solidity, `import "foo";` does not check path relative to the currrent
file, only `import "./foo";` does.

This work is also a re-write of hyperledger-solang#1443

Signed-off-by: Sean Young <[email protected]>
seanyoung added a commit to seanyoung/solang that referenced this pull request Aug 10, 2023
When importing in Solidity, `import "foo";` does not check path relative to the currrent
file, only `import "./foo";` does.

This work is also a re-write of hyperledger-solang#1443

Signed-off-by: Sean Young <[email protected]>
seanyoung added a commit that referenced this pull request Aug 10, 2023
…no (#1465)

When importing in Solidity, `import "foo";` does not check path relative
to the currrent file, only `import "./foo";` does.

This work is also a re-write of
#1443

Signed-off-by: Sean Young <[email protected]>
Co-authored-by: Cyrill Leutwiler <[email protected]>
@seanyoung
Copy link
Contributor

Fixed by #1465

@seanyoung seanyoung closed this Aug 11, 2023
@BenTheKush BenTheKush deleted the benku/option-import-path branch August 15, 2023 04:07
stainless-app bot pushed a commit to 2lambda123/hyperledger-solang that referenced this pull request Feb 4, 2024
…no (#1465)

When importing in Solidity, `import "foo";` does not check path relative
to the currrent file, only `import "./foo";` does.

This work is also a re-write of
hyperledger-solang/solang#1443

Signed-off-by: Sean Young <[email protected]>
Co-authored-by: Cyrill Leutwiler <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants