Never pin the scene to hardhat's implicit default solc#79
Merged
Conversation
Three stacked fixes for wrong-compiler scenes, found on a real project whose hardhat.config.js is a brownie-generated network-only stub: - hardhat_config_extractor.js now reports whether the user config actually has a `solidity` entry (hre.userConfig); when it doesn't, HardhatManager ignores the resolved version (hardhat's own built-in 0.7.3 default) so compilation falls back to DEFAULT_SOLC_VERSION + per-contract pragma resolution instead of pinning an all-^0.8.0 scene to solc7.3. - _detect_compiler_version_mismatch now matches the ParserError marker across solc's hard-wrapped lines (same class as the Yul stack-too-deep wrap fix), so the pragma-re-derivation workaround actually fires. - The compiler_version_mismatch workaround is enabled even when a global solc is configured: the detector only fires when that compiler provably cannot parse a file, and compiler_map is seeded up front, so a per-contract override is always safe. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
On a hardhat project whose
hardhat.config.jshas nosolidityentry (e.g. a brownie-generated network-only stub),npx hardhat config --jsonreports hardhat's built-in default compiler (0.7.3).HardhatManagertook that as the project's compiler and pinned the entire scene tosolc7.3viacompiler_map— on an all-^0.8.0codebase every file (including our own injectedDummyERC20Impl) fails withParserError: Source file requires different compiler version, and compilation analysis dies before any workaround can help.Two additional defects kept the existing recovery path from firing:
_detect_compiler_version_mismatchmatched the ParserError phrase within a single line, but solc hard-wraps its diagnostics (same class as the Yul stack-too-deep wrap bug fixed earlier).compiler_version_mismatchworkaround was registered withenabled=not solc_already_set, i.e. disabled exactly when a build system pinned a wrong global solc.Fix
hardhat_config_extractor.jsadditionally emitssolidityImplicitDefault: hre.userConfig.solidity === undefined. When set,HardhatManagerignores the resolved compiler (logging why) and leavessolc_version=None, so compilation falls back toDEFAULT_SOLC_VERSION+ per-contract pragma resolution.\s+between words), then maps the match back to a line index for the existing path/pragma context extraction._seed_compile_mapspromotes the scalar intocompiler_mapup front, so a per-contract override is always safe.Validation
solidityImplicitDefault: true, resolved 0.7.3 ignored) and a project with an explicitsolidityblock (false, 0.8.28 kept).🤖 Generated with Claude Code