Skip to content

Commit

Permalink
Merge pull request NomicFoundation#2038 from nomiclabs/solc-remapping
Browse files Browse the repository at this point in the history
Print warning when user tries to use solc remapping
  • Loading branch information
zoeyTM authored Nov 8, 2021
2 parents d442b58 + 33354e2 commit 379342f
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tender-beers-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hardhat": patch
---

Print warning when user tries to use solc remapping (#1877)
24 changes: 23 additions & 1 deletion packages/hardhat-core/src/internal/core/config/config-loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export function loadConfigAndTasks(

if (showSolidityConfigWarnings) {
checkUnsupportedSolidityConfig(resolved);
checkUnsupportedRemappings(resolved);
}

return resolved;
Expand Down Expand Up @@ -223,7 +224,7 @@ function checkMissingSolidityConfig(userConfig: any) {
if (userConfig.solidity === undefined) {
console.warn(
chalk.yellow(
`Solidity compiler is not configured. Version ${DEFAULT_SOLC_VERSION} will be used by default. Add a 'solidity' entry to your configuration to supress this warning.
`Solidity compiler is not configured. Version ${DEFAULT_SOLC_VERSION} will be used by default. Add a 'solidity' entry to your configuration to suppress this warning.
Learn more about compiler configuration at https://hardhat.org/config"
`
Expand Down Expand Up @@ -261,3 +262,24 @@ Learn more at https://hardhat.org/reference/solidity-support
);
}
}

function checkUnsupportedRemappings({ solidity }: HardhatConfig) {
const solcConfigs = [
...solidity.compilers,
...Object.values(solidity.overrides),
];
const remappings = solcConfigs.filter(
({ settings }) => settings.remappings !== undefined
);

if (remappings.length > 0) {
console.warn(
chalk.yellow(
`Solidity remappings are not currently supported; you may experience unexpected compilation results. Remove any 'remappings' fields from your configuration to suppress this warning.
Learn more about compiler configuration at https://hardhat.org/config
`
)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
solidity: {
compilers: [
{
version: "0.7.0",
settings: {
remappings: [":g=/dir"],
},
},
],
overrides: {
"contracts/Foo.sol": { version: "0.7.0" },
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
solidity: {
compilers: [
{
version: "0.7.0",
},
],
overrides: {
"contracts/Foo.sol": {
version: "0.7.0",
settings: {
remappings: [":g=/dir"],
},
},
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
solidity: {
version: "0.7.0",
settings: {
remappings: [":g=/dir"],
},
},
};
45 changes: 45 additions & 0 deletions packages/hardhat-core/test/internal/core/config/config-loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,5 +423,50 @@ Hardhat plugin instead.`
assert.equal(consoleWarnStub.callCount, 1);
assert.include(consoleWarnStub.args[0][0], "is not fully supported yet");
});

it("should emit a warning if there is a remapping in the compiler settings", function () {
loadConfigAndTasks(
{
config: "remapping-in-settings.js",
},
{ showSolidityConfigWarnings: true }
);

assert.equal(consoleWarnStub.callCount, 1);
assert.include(
consoleWarnStub.args[0][0],
"remappings are not currently supported"
);
});

it("should emit a warning if there is a remapping in the list of compiler settings", function () {
loadConfigAndTasks(
{
config: "remapping-in-list.js",
},
{ showSolidityConfigWarnings: true }
);

assert.equal(consoleWarnStub.callCount, 1);
assert.include(
consoleWarnStub.args[0][0],
"remappings are not currently supported"
);
});

it("should emit a warning if there is a remapping in the list of compiler overrides", function () {
loadConfigAndTasks(
{
config: "remapping-in-override.js",
},
{ showSolidityConfigWarnings: true }
);

assert.equal(consoleWarnStub.callCount, 1);
assert.include(
consoleWarnStub.args[0][0],
"remappings are not currently supported"
);
});
});
});

0 comments on commit 379342f

Please sign in to comment.