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

DeclarationError: Function with same name and parameter types defined twice. #769

Closed
DamirS09 opened this issue Nov 14, 2022 · 13 comments
Closed

Comments

@DamirS09
Copy link

Hi, I get an error with np hardhat coverage, I also used 0.7.2
image

@anuprshetty
Copy link

anuprshetty commented May 26, 2023

I got the same error. Anyone please help.

I have flattened a solidity file in hardhat project.
pragma solidity ^0.8.0;
hardhat version: 2.14.0
solidity-coverage: v0.8.2

Ran the below command:
npx hardhat coverage

It is giving the error same as in the screenshot #769 (comment)

@cgewecke and @area please help on this. The tool is really good. But just stuck on this error.

@cgewecke
Copy link
Member

Does anyone have reproduction steps for this?

@DamirS09
Copy link
Author

Does anyone have reproduction steps for this?

the problem with redefinition was not working with virtual and ovveride

@cgewecke
Copy link
Member

cgewecke commented Sep 22, 2023

@Bubble7777 So it's still an issue? Could you give a simple example to help me understand what's going wrong?

@anuprshetty
Copy link

anuprshetty commented Oct 5, 2023

I understood the root cause.
This issue caused when you have diamond inheritance dependency for your contract and you have flattened the file.

Example:
D
/ \
B C
\ /
A

Here my contract A inherits contracts B and C. Internally lets say B and C inherits same contract D.
With this setup, flatten the file. So all contracts A, B, C, and D are placed in the same file.

Now if you run solidity-coverage on this file, this error occurs.

@cgewecke
Copy link
Member

Have tried to reproduce this in #836 following the advice the comment above but ... no luck. Everything compiles. If anyone can provide a simple reproduction case for this to investigate, will re-open and take another look.

@tanujdamani
Copy link

tanujdamani commented Feb 16, 2024

Was able to replicate this problem for a basic contract and gives the same error when running coverage on the flattened file.

Here is how to replicate:

All files can be found here: https://gist.github.com/tanujdamani/56a4fd8460ce4546913eb715d9366dc3

  1. Created a simple ERC721 contract with AccessControl using the OZ Wizard. (Added Strings and the tokenURI override function.)
  2. This is the contract simpleContract.sol
  3. This file was flattened using hardhat. npx hardhat flatten contracts/simpleContract.sol > simplyFlat.sol
  4. This is the flattened contract simplyFlat.sol
  5. Moved the new contract simplyFlat.sol to the contracts/ folder.
  6. Then checked coverage by running this command: npx hardhat coverage
  7. This gave the following errors.
  8. Running the command with --show-stack-traces additionally returned the following lines:
HardhatPluginError: HardhatError: HH600: Compilation failed
    at SimpleTaskDefinition.action (/Users/tj/Developer/simpleContract/node_modules/solidity-coverage/plugins/hardhat.plugin.js:274:35)
    at Environment._runTaskDefinition (/Users/tj/Developer/simpleContract/node_modules/hardhat/src/internal/core/runtime-environment.ts:358:14)
    at Environment.run (/Users/tj/Developer/simpleContract/node_modules/hardhat/src/internal/core/runtime-environment.ts:191:14)
    at main (/Users/tj/Developer/simpleContract/node_modules/hardhat/src/internal/cli/cli.ts:323:7)

Additional Information:

  • hardhat: v2.20.0
  • @openzeppelin/contracts: v4.9.5
  • @nomicfoundation/hardhat-toolbox: v4.0.0

Edited the comment and moved all the code to a gist.

@cgewecke
Copy link
Member

@tanujdamani Nice work, thank you. Will take a look...

@cgewecke
Copy link
Member

A patch for this has been merged in #865 and will be published in the next release (0.8.8).

A workaround before then is to make sure there is only a single pragma at the top of the flattened file.

The coverage plugin has a bug where it (incorrectly) assumes it will only encounter one and injects illegal duplicate instrumentation when this is not the case.

Thanks again @tanujdamani for reproducing this!

@tanujdamani
Copy link

Thanks @cgewecke for the quick action!

I've done a check on the coverage by removing all the additional pragma lines. I still think there might be an issue. Thought the errors have reduced drastically.

  1. Updated flattened file: simplyFlatv2.sol
  2. Remaining Errors: errors-v2.txt
  3. Here are the stack trace output (same as before):
HardhatPluginError: HardhatError: HH600: Compilation failed
    at SimpleTaskDefinition.action (/Users/tj/Developer/simpleContract/node_modules/solidity-coverage/plugins/hardhat.plugin.js:274:35)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Environment._runTaskDefinition (/Users/tj/Developer/simpleContract/node_modules/hardhat/src/internal/core/runtime-environment.ts:358:14)
    at Environment.run (/Users/tj/Developer/simpleContract/node_modules/hardhat/src/internal/core/runtime-environment.ts:191:14)
    at main (/Users/tj/Developer/simpleContract/node_modules/hardhat/src/internal/cli/cli.ts:323:7)

@cgewecke
Copy link
Member

@tanujdamani Ah! There are still a couple stray pragmas in your updated file. (I found these in text editor, the gist is a little difficult to search).

  • Line 1114
  • Line 1828

If those are removed it looks like it will compile after being instrumented

@tanujdamani
Copy link

@cgewecke You are absolutely right. Sorry for that. After removing those pragma lines, it worked as expected. This definitely is a decent workaround while we wait for the merge. Thanks again!

@cgewecke
Copy link
Member

Published with 0.8.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants