Skip to content

Commit 8696e2c

Browse files
mo-hakIGI-111sdankeljjcnnJoshuaBatty
authored
CompileError::ContractIdConstantNotAConstDecl (#6842)
## Description In contract_helpers.rs, replaced the ContractIdConstantNotAConstDecl error with an Internal compiler error since this represents an impossible state that should never occur in normal operation. In error.rs, removed the now unused ContractIdConstantNotAConstDecl error variant and its corresponding span implementation. The changes make sense because: The error was only used in one place where it represented an impossible state If that state is ever reached, it indicates a bug in the compiler itself rather than user error Using an internal compiler error will make it clearer that this is a compiler bug that needs to be fixed if it ever occurs fix #6841 ## Checklist - [x] I have linked to any relevant issues. - [ ] I have commented my code, particularly in hard-to-understand areas. - [ ] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [ ] I have added tests that prove my fix is effective or that my feature works. - [ ] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. --------- Co-authored-by: IGI-111 <igi-111@protonmail.com> Co-authored-by: Sophie Dankel <47993817+sdankel@users.noreply.github.com> Co-authored-by: jjcnn <38888011+jjcnn@users.noreply.github.com> Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
1 parent 0de1c32 commit 8696e2c

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

sway-core/src/semantic_analysis/namespace/contract_helpers.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,13 @@ fn bind_contract_id_in_root_module(
9999
let type_check_ctx =
100100
TypeCheckContext::from_namespace(&mut namespace, &mut symbol_ctx, engines, experimental);
101101
// Typecheck the const declaration. This will add the binding in the supplied namespace
102-
match TyAstNode::type_check(handler, type_check_ctx, &ast_node)
103-
.unwrap()
104-
.content
105-
{
106-
TyAstNodeContent::Declaration(_) => Ok(namespace.root()),
107-
_ => Err(
108-
handler.emit_err(CompileError::ContractIdConstantNotAConstDecl {
109-
span: const_item_span,
110-
}),
111-
),
102+
let type_checked = TyAstNode::type_check(handler, type_check_ctx, &ast_node).unwrap();
103+
if let TyAstNodeContent::Declaration(_) = type_checked.content {
104+
Ok(namespace.root())
105+
} else {
106+
Err(handler.emit_err(CompileError::Internal(
107+
"Contract ID declaration did not typecheck to a declaration, which should be impossible",
108+
const_item_span,
109+
)))
112110
}
113111
}

sway-error/src/error.rs

-5
Original file line numberDiff line numberDiff line change
@@ -917,10 +917,6 @@ pub enum CompileError {
917917
ContinueOutsideLoop { span: Span },
918918
/// This will be removed once loading contract IDs in a dependency namespace is refactored and no longer manual:
919919
/// https://github.com/FuelLabs/sway/issues/3077
920-
#[error("Contract ID is not a constant item.")]
921-
ContractIdConstantNotAConstDecl { span: Span },
922-
/// This will be removed once loading contract IDs in a dependency namespace is refactored and no longer manual:
923-
/// https://github.com/FuelLabs/sway/issues/3077
924920
#[error("Contract ID value is not a literal.")]
925921
ContractIdValueNotALiteral { span: Span },
926922

@@ -1231,7 +1227,6 @@ impl Spanned for CompileError {
12311227
IntrinsicIncorrectNumTArgs { span, .. } => span.clone(),
12321228
BreakOutsideLoop { span } => span.clone(),
12331229
ContinueOutsideLoop { span } => span.clone(),
1234-
ContractIdConstantNotAConstDecl { span } => span.clone(),
12351230
ContractIdValueNotALiteral { span } => span.clone(),
12361231
RefMutableNotAllowedInMain { span, .. } => span.clone(),
12371232
InitializedRegisterReassignment { span, .. } => span.clone(),

0 commit comments

Comments
 (0)