diff --git a/sway-core/src/control_flow_analysis/analyze_return_paths.rs b/sway-core/src/control_flow_analysis/analyze_return_paths.rs index 432daa72a38..ef46140c4b5 100644 --- a/sway-core/src/control_flow_analysis/analyze_return_paths.rs +++ b/sway-core/src/control_flow_analysis/analyze_return_paths.rs @@ -261,7 +261,7 @@ fn connect_declaration( Ok(leaves.to_vec()) } ErrorRecovery => Ok(leaves.to_vec()), - Break => { + Break { .. } => { let entry_node = graph.add_node(node.into()); for leaf in leaves { graph.add_edge(*leaf, entry_node, "".into()); @@ -274,7 +274,7 @@ fn connect_declaration( None => Err(CompileError::BreakOutsideLoop { span }), } } - Continue => { + Continue { .. } => { let entry_node = graph.add_node(node.into()); for leaf in leaves { graph.add_edge(*leaf, entry_node, "".into()); diff --git a/sway-core/src/control_flow_analysis/dead_code_analysis.rs b/sway-core/src/control_flow_analysis/dead_code_analysis.rs index a39820021d8..d3f5d86e04b 100644 --- a/sway-core/src/control_flow_analysis/dead_code_analysis.rs +++ b/sway-core/src/control_flow_analysis/dead_code_analysis.rs @@ -419,7 +419,7 @@ fn connect_declaration( Ok(leaves.to_vec()) } ErrorRecovery | GenericTypeForFunctionScope { .. } => Ok(leaves.to_vec()), - Break | Continue => Ok(vec![]), + Break { .. } | Continue { .. } => Ok(vec![]), } } diff --git a/sway-core/src/convert_parse_tree.rs b/sway-core/src/convert_parse_tree.rs index 654fb466fe1..c4c1ab7eb02 100644 --- a/sway-core/src/convert_parse_tree.rs +++ b/sway-core/src/convert_parse_tree.rs @@ -336,10 +336,14 @@ fn item_to_ast_nodes(ec: &mut ErrorContext, item: Item) -> Result, )] } ItemKind::Break(_) => { - vec![AstNodeContent::Declaration(Declaration::Break)] + vec![AstNodeContent::Declaration(Declaration::Break { + span: span.clone(), + })] } ItemKind::Continue(_) => { - vec![AstNodeContent::Declaration(Declaration::Continue)] + vec![AstNodeContent::Declaration(Declaration::Continue { + span: span.clone(), + })] } }; Ok(contents diff --git a/sway-core/src/ir_generation/compile.rs b/sway-core/src/ir_generation/compile.rs index 8e2fae8b11f..16cdc89a68e 100644 --- a/sway-core/src/ir_generation/compile.rs +++ b/sway-core/src/ir_generation/compile.rs @@ -130,8 +130,8 @@ fn compile_declarations( | TypedDeclaration::GenericTypeForFunctionScope { .. } | TypedDeclaration::StorageDeclaration(_) | TypedDeclaration::ErrorRecovery - | TypedDeclaration::Break - | TypedDeclaration::Continue => (), + | TypedDeclaration::Break { .. } + | TypedDeclaration::Continue { .. } => (), } } Ok(()) diff --git a/sway-core/src/ir_generation/function.rs b/sway-core/src/ir_generation/function.rs index de483509ffd..70c79cf4f2f 100644 --- a/sway-core/src/ir_generation/function.rs +++ b/sway-core/src/ir_generation/function.rs @@ -85,8 +85,8 @@ impl FnCompiler { ast_block.contents.clone().into_iter().position(|r| { matches!( r.content, - TypedAstNodeContent::Declaration(TypedDeclaration::Break) - | TypedAstNodeContent::Declaration(TypedDeclaration::Continue) + TypedAstNodeContent::Declaration(TypedDeclaration::Break { .. }) + | TypedAstNodeContent::Declaration(TypedDeclaration::Continue { .. }) ) }); diff --git a/sway-core/src/parse_tree/declaration.rs b/sway-core/src/parse_tree/declaration.rs index d2a5645a646..e18a4af0184 100644 --- a/sway-core/src/parse_tree/declaration.rs +++ b/sway-core/src/parse_tree/declaration.rs @@ -33,6 +33,6 @@ pub enum Declaration { AbiDeclaration(AbiDeclaration), ConstantDeclaration(ConstantDeclaration), StorageDeclaration(StorageDeclaration), - Break, - Continue, + Break { span: sway_types::Span }, + Continue { span: sway_types::Span }, } diff --git a/sway-core/src/semantic_analysis/ast_node/declaration.rs b/sway-core/src/semantic_analysis/ast_node/declaration.rs index 6cfc421b755..23236fc6ecd 100644 --- a/sway-core/src/semantic_analysis/ast_node/declaration.rs +++ b/sway-core/src/semantic_analysis/ast_node/declaration.rs @@ -38,8 +38,8 @@ pub enum TypedDeclaration { ErrorRecovery, StorageDeclaration(TypedStorageDeclaration), StorageReassignment(TypeCheckedStorageReassignment), - Break, - Continue, + Break { span: Span }, + Continue { span: Span }, } impl CopyTypes for TypedDeclaration { @@ -57,10 +57,13 @@ impl CopyTypes for TypedDeclaration { Reassignment(ref mut reassignment) => reassignment.copy_types(type_mapping), ImplTrait(impl_trait) => impl_trait.copy_types(type_mapping), // generics in an ABI is unsupported by design - AbiDeclaration(..) => (), - StorageDeclaration(..) => (), - StorageReassignment(..) => (), - GenericTypeForFunctionScope { .. } | ErrorRecovery | Break | Continue => (), + AbiDeclaration(..) + | StorageDeclaration(..) + | StorageReassignment(..) + | GenericTypeForFunctionScope { .. } + | ErrorRecovery + | Break { .. } + | Continue { .. } => (), } } } @@ -86,7 +89,7 @@ impl Spanned for TypedDeclaration { ImplTrait(TypedImplTrait { span, .. }) => span.clone(), StorageDeclaration(decl) => decl.span(), StorageReassignment(decl) => decl.span(), - ErrorRecovery | GenericTypeForFunctionScope { .. } | Break | Continue => { + ErrorRecovery | GenericTypeForFunctionScope { .. } | Break { .. } | Continue { .. } => { unreachable!("No span exists for these ast node types") } } @@ -205,8 +208,8 @@ impl UnresolvedTypeCheck for TypedDeclaration { | ImplTrait { .. } | AbiDeclaration(_) | GenericTypeForFunctionScope { .. } - | Break - | Continue => vec![], + | Break { .. } + | Continue { .. } => vec![], } } } @@ -373,8 +376,8 @@ impl TypedDeclaration { ErrorRecovery => "error", StorageDeclaration(_) => "contract storage declaration", StorageReassignment(_) => "contract storage reassignment", - Break => "break", - Continue => "continue", + Break { .. } => "break", + Continue { .. } => "continue", } } @@ -425,8 +428,8 @@ impl TypedDeclaration { | StorageReassignment { .. } | AbiDeclaration(..) | ErrorRecovery - | Break - | Continue => Visibility::Public, + | Break { .. } + | Continue { .. } => Visibility::Public, VariableDeclaration(TypedVariableDeclaration { is_mutable, .. }) => { is_mutable.visibility() } diff --git a/sway-core/src/semantic_analysis/ast_node/mod.rs b/sway-core/src/semantic_analysis/ast_node/mod.rs index 670ec8a7512..b1734ee2f43 100644 --- a/sway-core/src/semantic_analysis/ast_node/mod.rs +++ b/sway-core/src/semantic_analysis/ast_node/mod.rs @@ -476,8 +476,8 @@ impl TypedAstNode { ); TypedDeclaration::StorageDeclaration(decl) } - Declaration::Break => TypedDeclaration::Break, - Declaration::Continue => TypedDeclaration::Continue, + Declaration::Break { span } => TypedDeclaration::Break { span }, + Declaration::Continue { span } => TypedDeclaration::Continue { span }, }) } AstNodeContent::Expression(expr) => { diff --git a/sway-core/src/semantic_analysis/node_dependencies.rs b/sway-core/src/semantic_analysis/node_dependencies.rs index 41b33c52b6e..4429eb42f07 100644 --- a/sway-core/src/semantic_analysis/node_dependencies.rs +++ b/sway-core/src/semantic_analysis/node_dependencies.rs @@ -374,8 +374,8 @@ impl Dependencies { deps.gather_from_typeinfo(type_info) }), // Nothing to do for `break` and `continue` - Declaration::Break => self, - Declaration::Continue => self, + Declaration::Break { .. } => self, + Declaration::Continue { .. } => self, } } @@ -705,8 +705,8 @@ fn decl_name(decl: &Declaration) -> Option { // Storage cannot be depended upon or exported Declaration::StorageDeclaration(_) => None, // Nothing depends on a `break` and `continue` - Declaration::Break => None, - Declaration::Continue => None, + Declaration::Break { .. } => None, + Declaration::Continue { .. } => None, } } diff --git a/sway-lsp/src/core/token.rs b/sway-lsp/src/core/token.rs index d074e36d10b..101bab6d4f1 100644 --- a/sway-lsp/src/core/token.rs +++ b/sway-lsp/src/core/token.rs @@ -281,8 +281,8 @@ fn handle_declaration(declaration: Declaration, tokens: &mut Vec) { tokens.push(token); } } - Declaration::Break => {} - Declaration::Continue => {} + Declaration::Break { .. } => {} + Declaration::Continue { .. } => {} }; } diff --git a/sway-lsp/src/core/traverse_typed_tree.rs b/sway-lsp/src/core/traverse_typed_tree.rs index 2933c3a0ad3..0e67d2bfda8 100644 --- a/sway-lsp/src/core/traverse_typed_tree.rs +++ b/sway-lsp/src/core/traverse_typed_tree.rs @@ -182,8 +182,8 @@ fn handle_declaration(declaration: &TypedDeclaration, tokens: &mut TokenMap) { } handle_expression(&storage_reassignment.rhs, tokens); } - TypedDeclaration::Break => {} - TypedDeclaration::Continue => {} + TypedDeclaration::Break { .. } => {} + TypedDeclaration::Continue { .. } => {} } }