Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

fix(solc): can parse secondary source locations #849

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion ethers-solc/src/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,7 @@ pub struct Error {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub source_location: Option<SourceLocation>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub secondary_source_locations: Vec<SourceLocation>,
pub secondary_source_locations: Vec<SecondarySourceLocation>,
pub r#type: String,
pub component: String,
pub severity: Severity,
Expand Down Expand Up @@ -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<String>,
pub start: Option<i32>,
pub end: Option<i32>,
pub message: Option<String>,
}

Expand Down
23 changes: 23 additions & 0 deletions ethers-solc/tests/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<MinimalCombinedArtifacts>::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());
}