From 189b6e0b2d3c5bc6c4a665cd1f17b8944ea6f8e6 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 31 Jan 2022 22:44:31 +0100 Subject: [PATCH] fix(solc): can parse secondary source locations --- ethers-solc/src/artifacts.rs | 9 ++++++++- ethers-solc/tests/project.rs | 23 +++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/ethers-solc/src/artifacts.rs b/ethers-solc/src/artifacts.rs index 5977b43c1..3df384615 100644 --- a/ethers-solc/src/artifacts.rs +++ b/ethers-solc/src/artifacts.rs @@ -1733,7 +1733,7 @@ pub struct Error { #[serde(default, skip_serializing_if = "Option::is_none")] pub source_location: Option, #[serde(default, skip_serializing_if = "Vec::is_empty")] - pub secondary_source_locations: Vec, + pub secondary_source_locations: Vec, pub r#type: String, pub component: String, pub severity: Severity, @@ -1845,6 +1845,13 @@ pub struct SourceLocation { pub file: String, pub start: i32, pub end: i32, +} + +#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)] +pub struct SecondarySourceLocation { + pub file: Option, + pub start: Option, + pub end: Option, pub message: Option, } diff --git a/ethers-solc/tests/project.rs b/ethers-solc/tests/project.rs index f7b362d7b..e095b01e7 100644 --- a/ethers-solc/tests/project.rs +++ b/ethers-solc/tests/project.rs @@ -378,3 +378,26 @@ fn can_flatten_file_with_duplicates() { assert_eq!(result.matches("contract FooBar {").count(), 1); assert_eq!(result.matches(";").count(), 1); } + +#[test] +fn can_detect_type_error() { + let project = TempProject::::dapptools().unwrap(); + + project + .add_source( + "Contract", + r#" + pragma solidity ^0.8.10; + + contract Contract { + function xyz() public { + require(address(0), "Error"); + } + } + "#, + ) + .unwrap(); + + let compiled = project.compile().unwrap(); + assert!(compiled.has_compiler_errors()); +}