This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
Allow version: "pragma"
to let you import across incompatible Solidity versions
#4439
Labels
Issue
Truffle's
version: "pragma"
feature is awesome! It lets you compile your contracts even if they are written for differing Solidity versions.Problem is, if you import a file with an incompatible version, Truffle just throws an error. In many situations (e.g. importing a
library
), there's nothing we can do about that...But there is a common situation that we can handle completely! If the importing file uses the imported file only to reference its contracts externally, then we can ensure this import works perfectly by doing these steps:
resolver.resolve
produce this generated (and version-compatible!) Solidity instead of reading the incompatible imported file from disk.Doing this would remove a lot of friction for use cases that involve writing contracts to interface externally with other on-chain contracts.
Steps to Reproduce
Create the following Solidity files:
A.sol
B.sol
Then, set
version: "pragma"
in the solc truffle-config and compile.Desired behavior
Truffle should observe the incompatible versions and regenerate
B.sol
on the fly (likely using the abi-to-sol functionality provided by @truffle/resolver). Compilation should just work.Note that this should work even if
B.sol
defines a contract with a name other thanB
; Truffle should look insideB.sol
to determine whatinterface
name to produce. This may not be feasible1, however, so perhaps we can treat "source file must match contract name" as an okay initial constraint? Blech.Actual Results
Right now, the
version: "pragma"
feature detects the incompatible versions and throws a friendly error about it.Environment
truffle version
): v5.4.19node --version
):npm --version
):Footnotes
It might not be feasible because we'd be forced to run abi-to-sol multiple times (once for each ABI produced when compiling a given source), and doing this has high risk of name collisions that would cause compilation to fail.
The open abi-to-sol issue https://github.com/gnidan/abi-to-sol/issues/41 describes this problem a bit further. ↩
The text was updated successfully, but these errors were encountered: