Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes unreachable on invalid cfg attribute arg. #6553

Merged
merged 1 commit into from
Sep 17, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -4943,8 +4943,13 @@ pub fn cfg_eval(
}
},
_ => {
// Already checked with `AttributeKind::expected_args_*`
unreachable!("cfg attribute should only have the `target` or the `program_type` argument");
return Err(handler.emit_err(
ConvertParseTreeError::InvalidCfgArg {
span: arg.span(),
value: arg.name.as_str().to_string(),
}
.into(),
));
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions sway-error/src/convert_parse_tree_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ pub enum ConvertParseTreeError {
ExpectedCfgProgramTypeArgValue { span: Span },
#[error("Expected \"true\" or \"false\" for experimental_new_encoding")]
ExpectedExperimentalNewEncodingArgValue { span: Span },
#[error("Unexpected attribute value: \"{value}\" for attribute: \"cfg\"")]
InvalidCfgArg { span: Span, value: String },
}

impl Spanned for ConvertParseTreeError {
Expand Down Expand Up @@ -182,6 +184,7 @@ impl Spanned for ConvertParseTreeError {
ConvertParseTreeError::InvalidCfgProgramTypeArgValue { span, .. } => span.clone(),
ConvertParseTreeError::ExpectedCfgProgramTypeArgValue { span } => span.clone(),
ConvertParseTreeError::ExpectedExperimentalNewEncodingArgValue { span } => span.clone(),
ConvertParseTreeError::InvalidCfgArg { span, .. } => span.clone(),
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "invalid_cfg_arg"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
name = "invalid_cfg_arg"
authors = ["Fuel Labs <[email protected]>"]
entry = "main.sw"
license = "Apache-2.0"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
predicate;
#[cfg(c)] a
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
category = "fail"

# check: $()#[cfg(c)] a
# nextln: $()Unexpected attribute value: "c" for attribute: "cfg" expected value "target" or "program_type" or "experimental_new_encoding"

# check: $()#[cfg(c)] a
# nextln: $()Expected an item.

# check: $()#[cfg(c)] a
# nextln: $()Unexpected attribute value: "c" for attribute: "cfg"
Loading