From 5fefb2b721595bb4bf271c39d9fa9d5c98831441 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 31 Jan 2022 22:54:49 +0100 Subject: [PATCH] fix(solc): can parse secondary source locations (#849) --- 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 5977b43c..3df38461 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 f7b362d7..e095b01e 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()); +}