Fix Hardhat compile error when library or interface has namespace struct, print warning for library #1086
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR addresses two issues:
When making modified solc input to extract storage layouts, we normally detect namespace annotated structs in contracts and insert corresponding storage variables in order to get the detailed storage layouts of those structs.
However, libraries and interfaces do not support storage variables, so we should skip this insertion for libraries and interfaces.
(Note that if contracts inherit interfaces, namespaces in those interfaces can still be validated but they won't have detailed type information such as slots or lengths)
Fixes #1066
ERC-7201 states, "Structs with this annotation found outside of contracts are not considered to be namespaces for any contract in the source code."
Storage layout validations can only occur on namespaces that we can detect in contracts and their inheritance (including inherited interfaces). Particularly, namespaces in libraries are NOT validated, although we can see from this GitHub query that it is quite common.
This PR also adds a warning (not an error, to avoid breaking changes) if namespaces are defined in libraries.