Skip to content

Never pin the scene to hardhat's implicit default solc#79

Merged
shellygr merged 2 commits into
masterfrom
shelly/hardhat-implicit-solc
Jul 16, 2026
Merged

Never pin the scene to hardhat's implicit default solc#79
shellygr merged 2 commits into
masterfrom
shelly/hardhat-implicit-solc

Conversation

@shellygr

Copy link
Copy Markdown
Contributor

Problem

On a hardhat project whose hardhat.config.js has no solidity entry (e.g. a brownie-generated network-only stub), npx hardhat config --json reports hardhat's built-in default compiler (0.7.3). HardhatManager took that as the project's compiler and pinned the entire scene to solc7.3 via compiler_map — on an all-^0.8.0 codebase every file (including our own injected DummyERC20Impl) fails with ParserError: 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:

  1. _detect_compiler_version_mismatch matched 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).
  2. The compiler_version_mismatch workaround was registered with enabled=not solc_already_set, i.e. disabled exactly when a build system pinned a wrong global solc.

Fix

  • hardhat_config_extractor.js additionally emits solidityImplicitDefault: hre.userConfig.solidity === undefined. When set, HardhatManager ignores the resolved compiler (logging why) and leaves solc_version=None, so compilation falls back to DEFAULT_SOLC_VERSION + per-contract pragma resolution.
  • The mismatch detector matches the marker phrase across wrapped lines (\s+ between words), then maps the match back to a line index for the existing path/pragma context extraction.
  • The workaround is enabled even when a global solc is configured: the detector only fires when that compiler provably cannot parse a file, and _seed_compile_maps promotes the scalar into compiler_map up front, so a per-contract override is always safe.

Validation

  • 7 new unit tests (wrapped + single-line detection with a verbatim captured output, loop behavior with a wrong global solc, hardhat config extraction with implicit/explicit/legacy shapes); full suite passes (234).
  • Extractor checked live in the mass-test container against a real brownie-stub project (solidityImplicitDefault: true, resolved 0.7.3 ignored) and a project with an explicit solidity block (false, 0.8.28 kept).
  • End-to-end re-run of the failing project on this branch: compilation analysis now resolves the scene from pragmas (solc8.34) and completes solc compilation; the run proceeds to the next phase.

🤖 Generated with Claude Code

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>
@shellygr
shellygr requested a review from jar-ben July 16, 2026 16:14

@jar-ben jar-ben left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@shellygr
shellygr merged commit 4696f0d into master Jul 16, 2026
2 checks passed
@shellygr
shellygr deleted the shelly/hardhat-implicit-solc branch July 16, 2026 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants