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

chore: remove duplicate span from FunctionReturnType #2546

Merged
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
6 changes: 3 additions & 3 deletions crates/noirc_frontend/src/ast/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ pub enum FunctionReturnType {
/// Returns type is not specified.
Default(Span),
/// Everything else.
Ty(UnresolvedType, Span),
Ty(UnresolvedType),
}

/// Describes the types of smart contract functions that are allowed.
Expand Down Expand Up @@ -692,7 +692,7 @@ impl FunctionReturnType {
pub fn get_type(&self) -> &UnresolvedTypeData {
match self {
FunctionReturnType::Default(_span) => &UnresolvedTypeData::Unit,
FunctionReturnType::Ty(typ, _span) => &typ.typ,
FunctionReturnType::Ty(typ) => &typ.typ,
}
}
}
Expand All @@ -701,7 +701,7 @@ impl Display for FunctionReturnType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FunctionReturnType::Default(_) => f.write_str(""),
FunctionReturnType::Ty(ty, _) => write!(f, "{ty}"),
FunctionReturnType::Ty(ty) => write!(f, "{ty}"),
}
}
}
2 changes: 1 addition & 1 deletion crates/noirc_frontend/src/ast/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl NoirFunction {
FunctionReturnType::Default(_) => {
UnresolvedType::without_span(UnresolvedTypeData::Unit)
}
FunctionReturnType::Ty(ty, _) => ty.clone(),
FunctionReturnType::Ty(ty) => ty.clone(),
}
}
pub fn name(&self) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion crates/noirc_frontend/src/hir/def_collector/dc_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ fn resolve_trait_methods(
let arguments = vecmap(parameters, |param| resolver.resolve_type(param.1.clone()));
let resolved_return_type = match return_type {
FunctionReturnType::Default(_) => None,
FunctionReturnType::Ty(unresolved_type, _span) => {
FunctionReturnType::Ty(unresolved_type) => {
Some(resolver.resolve_type(unresolved_type.clone()))
}
};
Expand Down
5 changes: 3 additions & 2 deletions crates/noirc_frontend/src/hir/type_check/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,9 @@ impl From<TypeCheckError> for Diagnostic {
Source::Comparison => format!("Unsupported types for comparison: {expected} and {actual}"),
Source::BinOp => format!("Unsupported types for binary operation: {expected} and {actual}"),
Source::Return(ret_ty, expr_span) => {
let ret_ty_span = match ret_ty {
FunctionReturnType::Default(span) | FunctionReturnType::Ty(_, span) => span
let ret_ty_span = match ret_ty.clone() {
FunctionReturnType::Default(span) => span,
FunctionReturnType::Ty(ty) => ty.span.unwrap(),
};

let mut diagnostic = Diagnostic::simple_error(format!("expected type {expected}, found type {actual}"), format!("expected {expected} because of return type"), ret_ty_span);
Expand Down
2 changes: 1 addition & 1 deletion crates/noirc_frontend/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ fn function_return_type() -> impl NoirParser<((Distinctness, Visibility), Functi
.then(spanned(parse_type()))
.or_not()
.map_with_span(|ret, span| match ret {
Some((head, (ty, span))) => (head, FunctionReturnType::Ty(ty, span)),
Some((head, (ty, _))) => (head, FunctionReturnType::Ty(ty)),
None => (
(Distinctness::DuplicationAllowed, Visibility::Private),
FunctionReturnType::Default(span),
Expand Down