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

Fix and improve errors when the entry fns cannot be generated #5824

Merged
merged 8 commits into from
Apr 9, 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
29 changes: 8 additions & 21 deletions sway-core/src/ir_generation/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use sway_types::{ident::Ident, integer_bits::IntegerBits, span::Spanned, Span};
use sway_utils::mapped_stack::MappedStack;

enum ConstEvalError {
CompileError(CompileError),
CompileError,
CannotBeEvaluatedToConst {
// This is not used at the moment because we do not give detailed description of why a
// const eval failed.
Expand Down Expand Up @@ -640,13 +640,7 @@ fn const_eval_typed_expr(
if index < count {
Some(items[index as usize].clone())
} else {
return Err(ConstEvalError::CompileError(
CompileError::ArrayOutOfBounds {
index,
count,
span: expr.span.clone(),
},
));
return Err(ConstEvalError::CompileError);
}
}
_ => {
Expand All @@ -657,10 +651,7 @@ fn const_eval_typed_expr(
}
}
ty::TyExpressionVariant::Ref(_) | ty::TyExpressionVariant::Deref(_) => {
return Err(ConstEvalError::CompileError(CompileError::Unimplemented(
"Constant references are currently not supported.",
expr.span.clone(),
)));
return Err(ConstEvalError::CompileError);
}
ty::TyExpressionVariant::Reassignment(_)
| ty::TyExpressionVariant::FunctionParameter
Expand Down Expand Up @@ -993,7 +984,7 @@ fn const_eval_intrinsic(
&targ.type_id,
&targ.span,
)
.map_err(ConstEvalError::CompileError)?;
.map_err(|_| ConstEvalError::CompileError)?;
Ok(Some(Constant {
ty: Type::get_uint64(lookup.context),
value: ConstantValue::Uint(ir_type.size(lookup.context).in_bytes()),
Expand All @@ -1009,7 +1000,7 @@ fn const_eval_intrinsic(
&type_id,
&val.span,
)
.map_err(ConstEvalError::CompileError)?;
.map_err(|_| ConstEvalError::CompileError)?;
Ok(Some(Constant {
ty: Type::get_uint64(lookup.context),
value: ConstantValue::Uint(ir_type.size(lookup.context).in_bytes()),
Expand All @@ -1024,7 +1015,7 @@ fn const_eval_intrinsic(
&targ.type_id,
&targ.span,
)
.map_err(ConstEvalError::CompileError)?;
.map_err(|_| ConstEvalError::CompileError)?;
Ok(Some(Constant {
ty: Type::get_uint64(lookup.context),
value: ConstantValue::Uint(
Expand All @@ -1041,17 +1032,13 @@ fn const_eval_intrinsic(
&targ.type_id,
&targ.span,
)
.map_err(ConstEvalError::CompileError)?;
.map_err(|_| ConstEvalError::CompileError)?;
match ir_type.get_content(lookup.context) {
TypeContent::StringSlice | TypeContent::StringArray(_) => Ok(Some(Constant {
ty: Type::get_unit(lookup.context),
value: ConstantValue::Unit,
})),
_ => Err(ConstEvalError::CompileError(
CompileError::NonStrGenericType {
span: targ.span.clone(),
},
)),
_ => Err(ConstEvalError::CompileError),
}
}
Intrinsic::ToStrArray => {
Expand Down
Loading
Loading