From b0f49a6213e8b003c98682e24a109d0a22bdf86a Mon Sep 17 00:00:00 2001 From: James Casey Date: Sat, 28 Feb 2026 20:38:36 +0000 Subject: [PATCH 1/2] Parser: attach comments to ExpressionStatement; handle Module.file_leading_comments (BT-976) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add collect_trailing_comment() — reads trailing_trivia from the last consumed token to capture end-of-line `//` comments - Update parse_module(), parse_method_body(), parse_block() to call collect_comment_attachment() before and collect_trailing_comment() after each expression parse, replacing ExpressionStatement::bare() - Handle empty-module edge case: file-level comments with no items are collected into Module.file_leading_comments; non-empty modules carry leading comments on the first item as ExpressionStatement.comments - Remove old manual comment collection loop from parse_module() that was incorrectly storing all file comments in file_leading_comments - Update 65 parser snapshots to reflect comments now correctly attached to ExpressionStatement nodes instead of file_leading_comments - Add 5 tests covering all new cases (BT-976 acceptance criteria) Co-Authored-By: Claude Sonnet 4.6 --- .../source_analysis/parser/declarations.rs | 7 +- .../src/source_analysis/parser/expressions.rs | 7 +- .../src/source_analysis/parser/mod.rs | 210 +++- ...er_tests__abstract_class_spawn_parser.snap | 28 +- .../compiler_tests__actor_spawn_parser.snap | 70 +- ...r_tests__actor_spawn_with_args_parser.snap | 177 ++-- ...er_tests__actor_state_mutation_parser.snap | 124 ++- ...r_tests__async_keyword_message_parser.snap | 70 +- ...ler_tests__async_unary_message_parser.snap | 70 +- ...mpiler_tests__async_with_await_parser.snap | 70 +- ...mpiler_tests__binary_operators_parser.snap | 259 ++++- ...compiler_tests__blocks_no_args_parser.snap | 119 ++- ..._tests__boundary_deeply_nested_parser.snap | 141 ++- ...sts__boundary_long_identifiers_parser.snap | 119 ++- ...r_tests__boundary_mixed_errors_parser.snap | 108 +- ...__boundary_unicode_identifiers_parser.snap | 102 +- ...ompiler_tests__cascade_complex_parser.snap | 97 +- .../compiler_tests__cascades_parser.snap | 86 +- ...iler_tests__character_literals_parser.snap | 103 +- ...mpiler_tests__class_definition_parser.snap | 28 +- .../compiler_tests__class_methods_parser.snap | 28 +- ...mpiler_tests__comment_handling_parser.snap | 201 +++- ..._control_flow_mutations_errors_parser.snap | 86 +- ..._tests__control_flow_mutations_parser.snap | 412 ++++++-- .../compiler_tests__empty_blocks_parser.snap | 119 ++- ...piler_tests__empty_method_body_parser.snap | 44 +- .../compiler_tests__error_message_parser.snap | 36 +- ..._error_recovery_invalid_syntax_parser.snap | 108 +- ...ror_recovery_malformed_message_parser.snap | 119 ++- ...r_recovery_unterminated_string_parser.snap | 97 +- ...mpiler_tests__expect_directive_parser.snap | 130 ++- ...tests__future_pattern_matching_parser.snap | 102 +- ...s__future_string_interpolation_parser.snap | 158 ++- .../compiler_tests__hello_world_parser.snap | 54 +- ...piler_tests__intrinsic_keyword_parser.snap | 36 +- .../compiler_tests__map_literals_parser.snap | 147 ++- .../compiler_tests__method_lookup_parser.snap | 60 +- ...ts__multi_keyword_complex_args_parser.snap | 119 ++- .../compiler_tests__nested_blocks_parser.snap | 119 ++- ...tests__nested_keyword_messages_parser.snap | 119 ++- ..._tests__sealed_class_violation_parser.snap | 36 +- ..._tests__sealed_method_override_parser.snap | 36 +- ...tests__stdlib_class_dictionary_parser.snap | 44 +- ...piler_tests__stdlib_class_list_parser.snap | 36 +- ...mpiler_tests__stdlib_class_set_parser.snap | 36 +- ...iler_tests__stdlib_class_tuple_parser.snap | 44 +- ...piler_tests__string_operations_parser.snap | 180 +++- ...er_tests__typed_class_warnings_parser.snap | 52 +- .../compiler_tests__typed_methods_parser.snap | 12 +- ...mpiler_tests__typed_value_type_parser.snap | 12 +- ...ompiler_tests__unary_operators_parser.snap | 217 ++-- ...tests__unicode_string_literals_parser.snap | 81 +- ...__value_type_multi_expr_method_parser.snap | 68 +- ...ts__value_type_param_collision_parser.snap | 68 +- ...piler_tests__while_true_simple_parser.snap | 131 ++- ...ler_tests__whitespace_handling_parser.snap | 141 ++- ...sts__workspace_binding_cascade_parser.snap | 20 +- ..._tests__workspace_binding_send_parser.snap | 20 +- ...ompiler_tests__ws_stdlib_array_parser.snap | 70 +- ...ompiler_tests__ws_stdlib_block_parser.snap | 114 +- ...piler_tests__ws_stdlib_boolean_parser.snap | 114 +- ...er_tests__ws_stdlib_dictionary_parser.snap | 191 +++- ...piler_tests__ws_stdlib_integer_parser.snap | 158 ++- ...compiler_tests__ws_stdlib_list_parser.snap | 70 +- ...er_tests__ws_stdlib_nil_object_parser.snap | 994 +++++++++++++++--- .../compiler_tests__ws_stdlib_nil_parser.snap | 794 ++++++++++++-- .../compiler_tests__ws_stdlib_set_parser.snap | 70 +- ...mpiler_tests__ws_stdlib_string_parser.snap | 136 ++- 68 files changed, 5328 insertions(+), 2906 deletions(-) diff --git a/crates/beamtalk-core/src/source_analysis/parser/declarations.rs b/crates/beamtalk-core/src/source_analysis/parser/declarations.rs index 1c7115b51..d10384cb6 100644 --- a/crates/beamtalk-core/src/source_analysis/parser/declarations.rs +++ b/crates/beamtalk-core/src/source_analysis/parser/declarations.rs @@ -796,9 +796,14 @@ impl Parser { && !(self.in_class_body && self.current_token().indentation_after_newline() == Some(0)) { let pos_before = self.current; + let mut comments = self.collect_comment_attachment(); let expr = self.parse_expression(); + comments.trailing = self.collect_trailing_comment(); let is_error = expr.is_error(); - body.push(ExpressionStatement::bare(expr)); + body.push(ExpressionStatement { + comments, + expression: expr, + }); // If parse_expression didn't consume any tokens (e.g. nesting // depth exceeded), break to avoid an infinite loop. diff --git a/crates/beamtalk-core/src/source_analysis/parser/expressions.rs b/crates/beamtalk-core/src/source_analysis/parser/expressions.rs index 2a3eda747..b414d6096 100644 --- a/crates/beamtalk-core/src/source_analysis/parser/expressions.rs +++ b/crates/beamtalk-core/src/source_analysis/parser/expressions.rs @@ -641,8 +641,13 @@ impl Parser { let mut body = Vec::new(); while !self.check(&TokenKind::RightBracket) && !self.is_at_end() { let pos_before = self.current; + let mut comments = self.collect_comment_attachment(); let expr = self.parse_expression(); - body.push(ExpressionStatement::bare(expr)); + comments.trailing = self.collect_trailing_comment(); + body.push(ExpressionStatement { + comments, + expression: expr, + }); // If parse_expression didn't consume any tokens (e.g. nesting // depth exceeded), break to avoid an infinite loop. diff --git a/crates/beamtalk-core/src/source_analysis/parser/mod.rs b/crates/beamtalk-core/src/source_analysis/parser/mod.rs index 833c9a3bb..2b1b6320b 100644 --- a/crates/beamtalk-core/src/source_analysis/parser/mod.rs +++ b/crates/beamtalk-core/src/source_analysis/parser/mod.rs @@ -50,11 +50,9 @@ //! assert_eq!(module.expressions.len(), 1); //! ``` -use crate::ast::{ - Comment, CommentAttachment, CommentKind, Expression, ExpressionStatement, Module, -}; +use crate::ast::{Comment, CommentAttachment, Expression, ExpressionStatement, Module}; #[cfg(test)] -use crate::ast::{Literal, MessageSelector}; +use crate::ast::{CommentKind, Literal, MessageSelector}; use crate::source_analysis::{Span, Token, TokenKind, Trivia, lex_with_eof}; use ecow::EcoString; @@ -619,6 +617,29 @@ impl Parser { } } + /// Collects a trailing end-of-line comment from the last consumed token's trailing trivia. + /// + /// After parsing a complete expression, call this to check whether there is a + /// `// comment` on the same source line as the expression's last token. The + /// lexer places same-line trailing comments in [`Token::trailing_trivia`], so + /// checking the previously-consumed token is sufficient — no look-ahead needed. + /// + /// Only `//` line comments are considered; doc comments (`///`) and block + /// comments (`/* */`) are ignored here (block comments can span multiple lines + /// and are already collected as leading comments by [`collect_comment_attachment`]). + pub(super) fn collect_trailing_comment(&self) -> Option { + if self.current == 0 { + return None; + } + let last_token = &self.tokens[self.current - 1]; + for trivia in last_token.trailing_trivia() { + if let super::Trivia::LineComment(text) = trivia { + return Some(Comment::line(text.clone(), last_token.span())); + } + } + None + } + /// Reports an error at the current token. pub(super) fn error(&mut self, message: impl Into) { let span = self.current_token().span(); @@ -719,26 +740,12 @@ impl Parser { let mut classes = Vec::new(); let mut method_definitions = Vec::new(); let mut expressions = Vec::new(); - let mut comments = Vec::new(); - - // Collect leading comments - for trivia in self.current_token().leading_trivia() { - if trivia.is_comment() { - comments.push(Comment { - content: trivia.as_str().into(), - span: start, // TODO: track trivia spans - kind: match trivia { - super::Trivia::LineComment(_) | super::Trivia::DocComment(_) => { - CommentKind::Line - } - super::Trivia::BlockComment(_) => CommentKind::Block, - super::Trivia::Whitespace(_) => continue, - }, - }); - } - } - // Parse statements until EOF + // Parse statements until EOF. + // Leading comments on each expression are collected by collect_comment_attachment() + // immediately before parse_expression(). Class and standalone-method definitions + // collect their own comments inside parse_class_definition() / + // parse_standalone_method_definition() via the same helper. while !self.is_at_end() { // Check if this looks like a class definition if self.is_at_class_definition() { @@ -748,9 +755,14 @@ impl Parser { let method_def = self.parse_standalone_method_definition(); method_definitions.push(method_def); } else { + let mut comments = self.collect_comment_attachment(); let expr = self.parse_expression(); + comments.trailing = self.collect_trailing_comment(); let is_error = expr.is_error(); - expressions.push(ExpressionStatement::bare(expr)); + expressions.push(ExpressionStatement { + comments, + expression: expr, + }); // If we got an error, try to recover if is_error { @@ -777,6 +789,16 @@ impl Parser { } } + // Empty module edge case: if the file contains only comments and no items, + // collect those comments into file_leading_comments. Non-empty modules carry + // their leading comments on the first item (class, method def, or expression). + let file_leading_comments = + if classes.is_empty() && method_definitions.is_empty() && expressions.is_empty() { + self.collect_comment_attachment().leading + } else { + Vec::new() + }; + // Get end span let end = if self.current > 0 { self.tokens[self.current - 1].span() @@ -790,7 +812,7 @@ impl Parser { method_definitions, expressions, span, - file_leading_comments: comments, + file_leading_comments, } } @@ -4708,4 +4730,142 @@ Actor subclass: Counter state.comments.leading[0].content ); } + + // ======================================================================== + // ExpressionStatement comment attachment tests (BT-976) + // ======================================================================== + + #[test] + fn expression_statement_leading_comment_in_method_body() { + // A `//` comment between two statements in a method body must appear as a + // leading comment on the second ExpressionStatement. + let source = "Object subclass: Foo\n go =>\n x := 1.\n // Step two\n y := 2\n"; + let module = parse_ok(source); + assert_eq!(module.classes.len(), 1); + let body = &module.classes[0].methods[0].body; + assert_eq!(body.len(), 2, "expected 2 statements"); + // First statement has no leading comment + assert!( + body[0].comments.leading.is_empty(), + "first statement should have no leading comment" + ); + // Second statement has the `// Step two` comment as leading + assert_eq!( + body[1].comments.leading.len(), + 1, + "expected one leading comment on second statement" + ); + assert!( + body[1].comments.leading[0].content.contains("Step two"), + "content: {}", + body[1].comments.leading[0].content + ); + } + + #[test] + fn expression_statement_trailing_comment() { + // A `// comment` on the same line as a statement must appear as `trailing` + // on that ExpressionStatement. + let source = "Object subclass: Foo\n go => x := 1 // inline note\n"; + let module = parse_ok(source); + assert_eq!(module.classes.len(), 1); + let body = &module.classes[0].methods[0].body; + assert_eq!(body.len(), 1, "expected 1 statement"); + assert!( + body[0].comments.trailing.is_some(), + "expected a trailing comment" + ); + assert!( + body[0] + .comments + .trailing + .as_ref() + .unwrap() + .content + .contains("inline note"), + "trailing content: {:?}", + body[0].comments.trailing + ); + } + + #[test] + fn empty_module_file_leading_comments_populated() { + // A `.bt` file containing only comments and no items must populate + // `Module.file_leading_comments`. + let source = "// First comment\n// Second comment\n"; + let (module, diagnostics) = parse(lex_with_eof(source)); + assert!(diagnostics.is_empty(), "expected no diagnostics"); + assert!(module.classes.is_empty()); + assert!(module.expressions.is_empty()); + assert_eq!( + module.file_leading_comments.len(), + 2, + "expected 2 file-level comments" + ); + assert!( + module.file_leading_comments[0].content.contains("First"), + "content: {}", + module.file_leading_comments[0].content + ); + assert!( + module.file_leading_comments[1].content.contains("Second"), + "content: {}", + module.file_leading_comments[1].content + ); + } + + #[test] + fn non_empty_module_file_leading_comments_empty() { + // In a non-empty module, file-level leading comments attach to the first + // item — `file_leading_comments` must remain empty. + let source = "// File comment\nx := 42\n"; + let (module, diagnostics) = parse(lex_with_eof(source)); + assert!(diagnostics.is_empty(), "expected no diagnostics"); + assert!( + module.file_leading_comments.is_empty(), + "file_leading_comments should be empty for non-empty module" + ); + assert_eq!(module.expressions.len(), 1); + // The comment attaches to the first expression's ExpressionStatement + assert_eq!( + module.expressions[0].comments.leading.len(), + 1, + "expected leading comment on first expression" + ); + assert!( + module.expressions[0].comments.leading[0] + .content + .contains("File comment"), + "content: {}", + module.expressions[0].comments.leading[0].content + ); + } + + #[test] + fn block_body_expression_statement_leading_comment() { + // A `//` comment between statements in a block body attaches as leading + // on the following ExpressionStatement in the block. + let source = "Object subclass: Foo\n go =>\n [:each |\n // Transform\n each asUppercase]\n"; + let module = parse_ok(source); + assert_eq!(module.classes.len(), 1); + let body = &module.classes[0].methods[0].body; + assert_eq!(body.len(), 1, "expected 1 statement in method body"); + // The statement is a block expression + let Expression::Block(block) = &body[0].expression else { + panic!("expected Block expression, got {:?}", body[0].expression); + }; + assert_eq!(block.body.len(), 1, "expected 1 statement in block"); + assert_eq!( + block.body[0].comments.leading.len(), + 1, + "expected leading comment on block statement" + ); + assert!( + block.body[0].comments.leading[0] + .content + .contains("Transform"), + "content: {}", + block.body[0].comments.leading[0].content + ); + } } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__abstract_class_spawn_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__abstract_class_spawn_parser.snap index 30abb1232..db79ee13b 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__abstract_class_spawn_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__abstract_class_spawn_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -151,30 +150,5 @@ Module { start: 145, end: 226, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 145, - end: 153, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 145, - end: 153, - }, - kind: Line, - }, - Comment { - content: "// Test that instantiating an abstract class produces a diagnostic error.", - span: Span { - start: 145, - end: 153, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__actor_spawn_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__actor_spawn_parser.snap index a98cd79c8..fdb0c8fd2 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__actor_spawn_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__actor_spawn_parser.snap @@ -9,7 +9,40 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 173, + end: 178, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 173, + end: 178, + }, + kind: Line, + }, + Comment { + content: "// Test actor spawn compilation", + span: Span { + start: 173, + end: 178, + }, + kind: Line, + }, + Comment { + content: "// The syntax \"Counter spawn\" should compile to gen_server:start_link", + span: Span { + start: 173, + end: 178, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -196,38 +229,5 @@ Module { start: 173, end: 257, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 173, - end: 178, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 173, - end: 178, - }, - kind: Line, - }, - Comment { - content: "// Test actor spawn compilation", - span: Span { - start: 173, - end: 178, - }, - kind: Line, - }, - Comment { - content: "// The syntax \"Counter spawn\" should compile to gen_server:start_link", - span: Span { - start: 173, - end: 178, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__actor_spawn_with_args_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__actor_spawn_with_args_parser.snap index c8378f494..e5f1dc088 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__actor_spawn_with_args_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__actor_spawn_with_args_parser.snap @@ -9,7 +9,88 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 368, + end: 373, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 368, + end: 373, + }, + kind: Line, + }, + Comment { + content: "// Test actor spawn with initialization arguments", + span: Span { + start: 368, + end: 373, + }, + kind: Line, + }, + Comment { + content: "// Counter spawnWith: passes initialization arguments to init/1", + span: Span { + start: 368, + end: 373, + }, + kind: Line, + }, + Comment { + content: "// which merges them with default field values.", + span: Span { + start: 368, + end: 373, + }, + kind: Line, + }, + Comment { + content: "//", + span: Span { + start: 368, + end: 373, + }, + kind: Line, + }, + Comment { + content: "// Once map literals are supported, use:", + span: Span { + start: 368, + end: 373, + }, + kind: Line, + }, + Comment { + content: "// counter := Counter spawnWith: #{value => 10}", + span: Span { + start: 368, + end: 373, + }, + kind: Line, + }, + Comment { + content: "//", + span: Span { + start: 368, + end: 373, + }, + kind: Line, + }, + Comment { + content: "// For now, test with a simple value:", + span: Span { + start: 368, + end: 373, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -148,7 +229,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Spawn with default values (value = 0)", + span: Span { + start: 469, + end: 477, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -196,86 +286,5 @@ Module { start: 368, end: 494, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 368, - end: 373, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 368, - end: 373, - }, - kind: Line, - }, - Comment { - content: "// Test actor spawn with initialization arguments", - span: Span { - start: 368, - end: 373, - }, - kind: Line, - }, - Comment { - content: "// Counter spawnWith: passes initialization arguments to init/1", - span: Span { - start: 368, - end: 373, - }, - kind: Line, - }, - Comment { - content: "// which merges them with default field values.", - span: Span { - start: 368, - end: 373, - }, - kind: Line, - }, - Comment { - content: "//", - span: Span { - start: 368, - end: 373, - }, - kind: Line, - }, - Comment { - content: "// Once map literals are supported, use:", - span: Span { - start: 368, - end: 373, - }, - kind: Line, - }, - Comment { - content: "// counter := Counter spawnWith: #{value => 10}", - span: Span { - start: 368, - end: 373, - }, - kind: Line, - }, - Comment { - content: "//", - span: Span { - start: 368, - end: 373, - }, - kind: Line, - }, - Comment { - content: "// For now, test with a simple value:", - span: Span { - start: 368, - end: 373, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__actor_state_mutation_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__actor_state_mutation_parser.snap index 0c5aa7ba5..82ad789f6 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__actor_state_mutation_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__actor_state_mutation_parser.snap @@ -9,7 +9,56 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 256, + end: 261, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 256, + end: 261, + }, + kind: Line, + }, + Comment { + content: "// Test actor state mutation with proper state threading", + span: Span { + start: 256, + end: 261, + }, + kind: Line, + }, + Comment { + content: "//", + span: Span { + start: 256, + end: 261, + }, + kind: Line, + }, + Comment { + content: "// Each assignment to self.field should update the actor's state,", + span: Span { + start: 256, + end: 261, + }, + kind: Line, + }, + Comment { + content: "// and the updated state should be returned to gen_server.", + span: Span { + start: 256, + end: 261, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -39,7 +88,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Single assignment - increments value by 1", + span: Span { + start: 314, + end: 323, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -182,7 +240,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Get current value (no mutation)", + span: Span { + start: 410, + end: 418, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -251,54 +318,5 @@ Module { start: 256, end: 438, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 256, - end: 261, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 256, - end: 261, - }, - kind: Line, - }, - Comment { - content: "// Test actor state mutation with proper state threading", - span: Span { - start: 256, - end: 261, - }, - kind: Line, - }, - Comment { - content: "//", - span: Span { - start: 256, - end: 261, - }, - kind: Line, - }, - Comment { - content: "// Each assignment to self.field should update the actor's state,", - span: Span { - start: 256, - end: 261, - }, - kind: Line, - }, - Comment { - content: "// and the updated state should be returned to gen_server.", - span: Span { - start: 256, - end: 261, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__async_keyword_message_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__async_keyword_message_parser.snap index a1ef4a743..6ef311d59 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__async_keyword_message_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__async_keyword_message_parser.snap @@ -9,7 +9,40 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 186, + end: 192, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 186, + end: 192, + }, + kind: Line, + }, + Comment { + content: "// Test async keyword message send within a method", + span: Span { + start: 186, + end: 192, + }, + kind: Line, + }, + Comment { + content: "// Uses a non-Dictionary selector to test async message protocol", + span: Span { + start: 186, + end: 192, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -110,38 +143,5 @@ Module { start: 186, end: 227, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 186, - end: 192, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 186, - end: 192, - }, - kind: Line, - }, - Comment { - content: "// Test async keyword message send within a method", - span: Span { - start: 186, - end: 192, - }, - kind: Line, - }, - Comment { - content: "// Uses a non-Dictionary selector to test async message protocol", - span: Span { - start: 186, - end: 192, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__async_unary_message_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__async_unary_message_parser.snap index 7b5529476..d4c2bfe8b 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__async_unary_message_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__async_unary_message_parser.snap @@ -9,7 +9,40 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 160, + end: 163, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 160, + end: 163, + }, + kind: Line, + }, + Comment { + content: "// Test async unary message send within a method", + span: Span { + start: 160, + end: 163, + }, + kind: Line, + }, + Comment { + content: "// Returns future from counter increment", + span: Span { + start: 160, + end: 163, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -76,38 +109,5 @@ Module { start: 160, end: 189, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 160, - end: 163, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 160, - end: 163, - }, - kind: Line, - }, - Comment { - content: "// Test async unary message send within a method", - span: Span { - start: 160, - end: 163, - }, - kind: Line, - }, - Comment { - content: "// Returns future from counter increment", - span: Span { - start: 160, - end: 163, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__async_with_await_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__async_with_await_parser.snap index 97f9de308..8c7a33c90 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__async_with_await_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__async_with_await_parser.snap @@ -9,7 +9,40 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 134, + end: 141, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 134, + end: 141, + }, + kind: Line, + }, + Comment { + content: "// Test await on a future", + span: Span { + start: 134, + end: 141, + }, + kind: Line, + }, + Comment { + content: "// Await blocks until future resolves", + span: Span { + start: 134, + end: 141, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -76,38 +109,5 @@ Module { start: 134, end: 162, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 134, - end: 141, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 134, - end: 141, - }, - kind: Line, - }, - Comment { - content: "// Test await on a future", - span: Span { - start: 134, - end: 141, - }, - kind: Line, - }, - Comment { - content: "// Await blocks until future resolves", - span: Span { - start: 134, - end: 141, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__binary_operators_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__binary_operators_parser.snap index 25a90c21d..685800947 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__binary_operators_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__binary_operators_parser.snap @@ -9,7 +9,48 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 241, + end: 249, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 241, + end: 249, + }, + kind: Line, + }, + Comment { + content: "// Test all binary operators for compilation verification", + span: Span { + start: 241, + end: 249, + }, + kind: Line, + }, + Comment { + content: "// Comprehensive coverage of all operators supported in Core Erlang codegen", + span: Span { + start: 241, + end: 249, + }, + kind: Line, + }, + Comment { + content: "// ===== Arithmetic Operators =====", + span: Span { + start: 241, + end: 249, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -315,7 +356,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ===== Comparison Operators =====", + span: Span { + start: 404, + end: 417, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -366,7 +416,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Loose inequality (/=)", + span: Span { + start: 454, + end: 472, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -417,7 +476,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Strict equality (=:=)", + span: Span { + start: 511, + end: 527, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -468,7 +536,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Strict inequality (=/=)", + span: Span { + start: 579, + end: 598, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -519,7 +596,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Less than", + span: Span { + start: 626, + end: 634, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -570,7 +656,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Greater than", + span: Span { + start: 662, + end: 673, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -621,7 +716,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Less than or equal", + span: Span { + start: 707, + end: 718, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -672,7 +776,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Greater than or equal", + span: Span { + start: 755, + end: 769, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -723,7 +836,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ===== String Concatenation =====", + span: Span { + start: 819, + end: 831, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -774,8 +896,34 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// ===== Complex Operator Expressions =====", + span: Span { + start: 973, + end: 984, + }, + kind: Line, + }, + Comment { + content: "// Operator precedence (binary operators are left-to-right in Smalltalk)", + span: Span { + start: 973, + end: 984, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// Should be (2 + 3) * 4 = 20", + span: Span { + start: 996, + end: 997, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -847,7 +995,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// Should be (10 - 5) / 2 = 2", + span: Span { + start: 1053, + end: 1054, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -918,7 +1075,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Nested operators", + span: Span { + start: 1107, + end: 1113, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1023,7 +1189,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Operators with blocks", + span: Span { + start: 1162, + end: 1173, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1127,7 +1302,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Operators in conditionals with defined variables", + span: Span { + start: 1250, + end: 1251, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1314,46 +1498,5 @@ Module { start: 241, end: 1299, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 241, - end: 249, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 241, - end: 249, - }, - kind: Line, - }, - Comment { - content: "// Test all binary operators for compilation verification", - span: Span { - start: 241, - end: 249, - }, - kind: Line, - }, - Comment { - content: "// Comprehensive coverage of all operators supported in Core Erlang codegen", - span: Span { - start: 241, - end: 249, - }, - kind: Line, - }, - Comment { - content: "// ===== Arithmetic Operators =====", - span: Span { - start: 241, - end: 249, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__blocks_no_args_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__blocks_no_args_parser.snap index ae6fc2163..3bd86d88f 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__blocks_no_args_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__blocks_no_args_parser.snap @@ -9,7 +9,48 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 171, + end: 177, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 171, + end: 177, + }, + kind: Line, + }, + Comment { + content: "// Test blocks with no arguments", + span: Span { + start: 171, + end: 177, + }, + kind: Line, + }, + Comment { + content: "// Empty parameter list is valid", + span: Span { + start: 171, + end: 177, + }, + kind: Line, + }, + Comment { + content: "// Simple block with no arguments", + span: Span { + start: 171, + end: 177, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -97,7 +138,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Block with no args that accesses outer scope", + span: Span { + start: 259, + end: 264, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -236,7 +286,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Block with no args as control structure condition", + span: Span { + start: 383, + end: 392, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -401,7 +460,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Multiple blocks with no args", + span: Span { + start: 489, + end: 495, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -545,46 +613,5 @@ Module { start: 171, end: 530, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 171, - end: 177, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 171, - end: 177, - }, - kind: Line, - }, - Comment { - content: "// Test blocks with no arguments", - span: Span { - start: 171, - end: 177, - }, - kind: Line, - }, - Comment { - content: "// Empty parameter list is valid", - span: Span { - start: 171, - end: 177, - }, - kind: Line, - }, - Comment { - content: "// Simple block with no arguments", - span: Span { - start: 171, - end: 177, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__boundary_deeply_nested_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__boundary_deeply_nested_parser.snap index 48fb28db8..11f1c6b70 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__boundary_deeply_nested_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__boundary_deeply_nested_parser.snap @@ -9,7 +9,48 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 243, + end: 250, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 243, + end: 250, + }, + kind: Line, + }, + Comment { + content: "// Test boundary condition: deeply nested expressions", + span: Span { + start: 243, + end: 250, + }, + kind: Line, + }, + Comment { + content: "// Stress test parser stack depth with multiple nesting levels", + span: Span { + start: 243, + end: 250, + }, + kind: Line, + }, + Comment { + content: "// Deeply nested parenthesized expressions (10 levels)", + span: Span { + start: 243, + end: 250, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -120,7 +161,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Deeply nested message sends (8 levels)", + span: Span { + start: 323, + end: 330, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -238,7 +288,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Deeply nested keyword messages (5 levels)", + span: Span { + start: 451, + end: 458, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -437,7 +496,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Deeply nested blocks (6 levels)", + span: Span { + start: 559, + end: 566, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -569,7 +637,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Complex mixed nesting (blocks + messages + operators)", + span: Span { + start: 643, + end: 650, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -754,7 +831,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Nested cascades with nested arguments (single line - multi-line cascades not yet supported)", + span: Span { + start: 786, + end: 793, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1183,48 +1269,7 @@ Module { start: 243, end: 900, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 243, - end: 250, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 243, - end: 250, - }, - kind: Line, - }, - Comment { - content: "// Test boundary condition: deeply nested expressions", - span: Span { - start: 243, - end: 250, - }, - kind: Line, - }, - Comment { - content: "// Stress test parser stack depth with multiple nesting levels", - span: Span { - start: 243, - end: 250, - }, - kind: Line, - }, - Comment { - content: "// Deeply nested parenthesized expressions (10 levels)", - span: Span { - start: 243, - end: 250, - }, - kind: Line, - }, - ], + file_leading_comments: [], } Diagnostics: diff --git a/test-package-compiler/tests/snapshots/compiler_tests__boundary_long_identifiers_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__boundary_long_identifiers_parser.snap index 3f05380d8..9921bc46d 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__boundary_long_identifiers_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__boundary_long_identifiers_parser.snap @@ -9,7 +9,48 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 218, + end: 319, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 218, + end: 319, + }, + kind: Line, + }, + Comment { + content: "// Test boundary condition: long identifiers and strings", + span: Span { + start: 218, + end: 319, + }, + kind: Line, + }, + Comment { + content: "// Validate parser handles extremely long tokens", + span: Span { + start: 218, + end: 319, + }, + kind: Line, + }, + Comment { + content: "// Very long identifier (100 characters)", + span: Span { + start: 218, + end: 319, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -39,7 +80,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Very long string literal (200+ characters)", + span: Span { + start: 373, + end: 383, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -69,7 +119,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Long keyword message selector (multiple long keywords)", + span: Span { + start: 662, + end: 668, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -171,7 +230,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Long identifier in nested context", + span: Span { + start: 873, + end: 916, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -239,48 +307,7 @@ Module { start: 218, end: 997, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 218, - end: 319, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 218, - end: 319, - }, - kind: Line, - }, - Comment { - content: "// Test boundary condition: long identifiers and strings", - span: Span { - start: 218, - end: 319, - }, - kind: Line, - }, - Comment { - content: "// Validate parser handles extremely long tokens", - span: Span { - start: 218, - end: 319, - }, - kind: Line, - }, - Comment { - content: "// Very long identifier (100 characters)", - span: Span { - start: 218, - end: 319, - }, - kind: Line, - }, - ], + file_leading_comments: [], } Diagnostics: diff --git a/test-package-compiler/tests/snapshots/compiler_tests__boundary_mixed_errors_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__boundary_mixed_errors_parser.snap index f04c27183..4376ce0e7 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__boundary_mixed_errors_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__boundary_mixed_errors_parser.snap @@ -9,7 +9,48 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 224, + end: 225, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 224, + end: 225, + }, + kind: Line, + }, + Comment { + content: "// Test boundary condition: mixed error scenarios", + span: Span { + start: 224, + end: 225, + }, + kind: Line, + }, + Comment { + content: "// Multiple errors in single expressions and compound statements", + span: Span { + start: 224, + end: 225, + }, + kind: Line, + }, + Comment { + content: "// Multiple syntax errors in one line", + span: Span { + start: 224, + end: 225, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -71,7 +112,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Unterminated string followed by valid code", + span: Span { + start: 287, + end: 290, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -160,7 +210,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Valid code after multiple errors should still parse", + span: Span { + start: 722, + end: 738, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -214,48 +273,7 @@ Module { start: 224, end: 751, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 224, - end: 225, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 224, - end: 225, - }, - kind: Line, - }, - Comment { - content: "// Test boundary condition: mixed error scenarios", - span: Span { - start: 224, - end: 225, - }, - kind: Line, - }, - Comment { - content: "// Multiple errors in single expressions and compound statements", - span: Span { - start: 224, - end: 225, - }, - kind: Line, - }, - Comment { - content: "// Multiple syntax errors in one line", - span: Span { - start: 224, - end: 225, - }, - kind: Line, - }, - ], + file_leading_comments: [], } Diagnostics: diff --git a/test-package-compiler/tests/snapshots/compiler_tests__boundary_unicode_identifiers_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__boundary_unicode_identifiers_parser.snap index eb5c0e399..c546aa4cf 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__boundary_unicode_identifiers_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__boundary_unicode_identifiers_parser.snap @@ -9,7 +9,56 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 323, + end: 326, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 323, + end: 326, + }, + kind: Line, + }, + Comment { + content: "// Test boundary condition: Unicode in identifiers and strings", + span: Span { + start: 323, + end: 326, + }, + kind: Line, + }, + Comment { + content: "// Validate proper UTF-8 handling in lexer and parser", + span: Span { + start: 323, + end: 326, + }, + kind: Line, + }, + Comment { + content: "// Unicode characters in identifiers (if supported)", + span: Span { + start: 323, + end: 326, + }, + kind: Line, + }, + Comment { + content: "// Note: This tests whether the lexer/parser gracefully handles or rejects Unicode", + span: Span { + start: 323, + end: 326, + }, + kind: Line, + }, + ], trailing: None, }, expression: Identifier( @@ -40,56 +89,7 @@ Module { start: 323, end: 800, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 323, - end: 326, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 323, - end: 326, - }, - kind: Line, - }, - Comment { - content: "// Test boundary condition: Unicode in identifiers and strings", - span: Span { - start: 323, - end: 326, - }, - kind: Line, - }, - Comment { - content: "// Validate proper UTF-8 handling in lexer and parser", - span: Span { - start: 323, - end: 326, - }, - kind: Line, - }, - Comment { - content: "// Unicode characters in identifiers (if supported)", - span: Span { - start: 323, - end: 326, - }, - kind: Line, - }, - Comment { - content: "// Note: This tests whether the lexer/parser gracefully handles or rejects Unicode", - span: Span { - start: 323, - end: 326, - }, - kind: Line, - }, - ], + file_leading_comments: [], } Diagnostics: diff --git a/test-package-compiler/tests/snapshots/compiler_tests__cascade_complex_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__cascade_complex_parser.snap index 36f1e47f0..09231b8d7 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__cascade_complex_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__cascade_complex_parser.snap @@ -9,7 +9,48 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 208, + end: 215, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 208, + end: 215, + }, + kind: Line, + }, + Comment { + content: "// Test complex cascade scenarios", + span: Span { + start: 208, + end: 215, + }, + kind: Line, + }, + Comment { + content: "// Multiple cascaded messages with different types", + span: Span { + start: 208, + end: 215, + }, + kind: Line, + }, + Comment { + content: "// Cascade with unary, binary, and keyword messages", + span: Span { + start: 208, + end: 215, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -112,7 +153,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Cascade with keyword messages", + span: Span { + start: 317, + end: 323, + }, + kind: Line, + }, + ], trailing: None, }, expression: Identifier( @@ -313,48 +363,7 @@ Module { start: 208, end: 612, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 208, - end: 215, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 208, - end: 215, - }, - kind: Line, - }, - Comment { - content: "// Test complex cascade scenarios", - span: Span { - start: 208, - end: 215, - }, - kind: Line, - }, - Comment { - content: "// Multiple cascaded messages with different types", - span: Span { - start: 208, - end: 215, - }, - kind: Line, - }, - Comment { - content: "// Cascade with unary, binary, and keyword messages", - span: Span { - start: 208, - end: 215, - }, - kind: Line, - }, - ], + file_leading_comments: [], } Diagnostics: diff --git a/test-package-compiler/tests/snapshots/compiler_tests__cascades_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__cascades_parser.snap index 26f7d15f3..ae0aa1343 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__cascades_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__cascades_parser.snap @@ -9,7 +9,48 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 208, + end: 218, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 208, + end: 218, + }, + kind: Line, + }, + Comment { + content: "// Test cascade message sends", + span: Span { + start: 208, + end: 218, + }, + kind: Line, + }, + Comment { + content: "// Sends multiple messages to the same receiver", + span: Span { + start: 208, + end: 218, + }, + kind: Line, + }, + Comment { + content: "// Method that uses a cascade - all messages go to counter", + span: Span { + start: 208, + end: 218, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -98,46 +139,5 @@ Module { start: 208, end: 264, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 208, - end: 218, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 208, - end: 218, - }, - kind: Line, - }, - Comment { - content: "// Test cascade message sends", - span: Span { - start: 208, - end: 218, - }, - kind: Line, - }, - Comment { - content: "// Sends multiple messages to the same receiver", - span: Span { - start: 208, - end: 218, - }, - kind: Line, - }, - Comment { - content: "// Method that uses a cascade - all messages go to counter", - span: Span { - start: 208, - end: 218, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__character_literals_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__character_literals_parser.snap index 4398eecde..24d962932 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__character_literals_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__character_literals_parser.snap @@ -9,7 +9,40 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 180, + end: 187, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 180, + end: 187, + }, + kind: Line, + }, + Comment { + content: "// Test character literal codegen - $a compiles to integer codepoint", + span: Span { + start: 180, + end: 187, + }, + kind: Line, + }, + Comment { + content: "// ===== Basic Character Literals =====", + span: Span { + start: 180, + end: 187, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -99,7 +132,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ===== Character Comparison =====", + span: Span { + start: 257, + end: 264, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -201,7 +243,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ===== Character Conversion =====", + span: Span { + start: 331, + end: 336, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -283,7 +334,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ===== Escape Sequences =====", + span: Span { + start: 407, + end: 414, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -346,38 +406,5 @@ Module { start: 180, end: 432, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 180, - end: 187, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 180, - end: 187, - }, - kind: Line, - }, - Comment { - content: "// Test character literal codegen - $a compiles to integer codepoint", - span: Span { - start: 180, - end: 187, - }, - kind: Line, - }, - Comment { - content: "// ===== Basic Character Literals =====", - span: Span { - start: 180, - end: 187, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__class_definition_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__class_definition_parser.snap index 84b686a41..4b1addaa7 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__class_definition_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__class_definition_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -256,30 +255,5 @@ Module { start: 104, end: 217, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 104, - end: 109, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 104, - end: 109, - }, - kind: Line, - }, - Comment { - content: "// Test class definition parsing", - span: Span { - start: 104, - end: 109, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__class_methods_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__class_methods_parser.snap index e59690b62..761c566bc 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__class_methods_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__class_methods_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -453,30 +452,5 @@ Module { start: 138, end: 422, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 138, - end: 143, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 138, - end: 143, - }, - kind: Line, - }, - Comment { - content: "// Test class method codegen (class-side methods, class variables)", - span: Span { - start: 138, - end: 143, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__comment_handling_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__comment_handling_parser.snap index 9c2598dbf..4fde08632 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__comment_handling_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__comment_handling_parser.snap @@ -9,8 +9,58 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 161, + end: 162, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 161, + end: 162, + }, + kind: Line, + }, + Comment { + content: "// Test comment handling", + span: Span { + start: 161, + end: 162, + }, + kind: Line, + }, + Comment { + content: "// Comments should be preserved as trivia", + span: Span { + start: 161, + end: 162, + }, + kind: Line, + }, + Comment { + content: "// Single line comment", + span: Span { + start: 161, + end: 162, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// inline comment", + span: Span { + start: 166, + end: 167, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -39,7 +89,32 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Multiple comments", + span: Span { + start: 244, + end: 245, + }, + kind: Line, + }, + Comment { + content: "// Comment line 1", + span: Span { + start: 244, + end: 245, + }, + kind: Line, + }, + Comment { + content: "// Comment line 2", + span: Span { + start: 244, + end: 245, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -69,7 +144,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Comment between expressions", + span: Span { + start: 284, + end: 285, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -99,7 +183,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Middle comment", + span: Span { + start: 309, + end: 310, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -129,8 +222,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Comment in message send", + span: Span { + start: 344, + end: 350, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// comment here", + span: Span { + start: 344, + end: 350, + }, + kind: Line, + }, + ), }, expression: Identifier( Identifier { @@ -145,7 +256,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// and here", + span: Span { + start: 380, + end: 385, + }, + kind: Line, + }, + ), }, expression: MessageSend { receiver: Error { @@ -168,7 +288,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Block with comments", + span: Span { + start: 422, + end: 427, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -187,7 +316,16 @@ Module { body: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Inside block", + span: Span { + start: 457, + end: 459, + }, + kind: Line, + }, + ], trailing: None, }, expression: Literal( @@ -218,48 +356,7 @@ Module { start: 161, end: 461, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 161, - end: 162, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 161, - end: 162, - }, - kind: Line, - }, - Comment { - content: "// Test comment handling", - span: Span { - start: 161, - end: 162, - }, - kind: Line, - }, - Comment { - content: "// Comments should be preserved as trivia", - span: Span { - start: 161, - end: 162, - }, - kind: Line, - }, - Comment { - content: "// Single line comment", - span: Span { - start: 161, - end: 162, - }, - kind: Line, - }, - ], + file_leading_comments: [], } Diagnostics: diff --git a/test-package-compiler/tests/snapshots/compiler_tests__control_flow_mutations_errors_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__control_flow_mutations_errors_parser.snap index 1058d8924..2bc4f8581 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__control_flow_mutations_errors_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__control_flow_mutations_errors_parser.snap @@ -9,7 +9,48 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 258, + end: 265, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 258, + end: 265, + }, + kind: Line, + }, + Comment { + content: "// Test error cases: stored closures should NOT allow mutations", + span: Span { + start: 258, + end: 265, + }, + kind: Line, + }, + Comment { + content: "// Per BT-90 design: only literal blocks in control flow positions can mutate", + span: Span { + start: 258, + end: 265, + }, + kind: Line, + }, + Comment { + content: "// ERROR: Field Assignment in Stored Closure", + span: Span { + start: 258, + end: 265, + }, + kind: Line, + }, + ], trailing: None, }, expression: Error { @@ -195,48 +236,7 @@ Module { start: 258, end: 635, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 258, - end: 265, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 258, - end: 265, - }, - kind: Line, - }, - Comment { - content: "// Test error cases: stored closures should NOT allow mutations", - span: Span { - start: 258, - end: 265, - }, - kind: Line, - }, - Comment { - content: "// Per BT-90 design: only literal blocks in control flow positions can mutate", - span: Span { - start: 258, - end: 265, - }, - kind: Line, - }, - Comment { - content: "// ERROR: Field Assignment in Stored Closure", - span: Span { - start: 258, - end: 265, - }, - kind: Line, - }, - ], + file_leading_comments: [], } Diagnostics: diff --git a/test-package-compiler/tests/snapshots/compiler_tests__control_flow_mutations_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__control_flow_mutations_parser.snap index 2db0dcc21..b86dac78a 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__control_flow_mutations_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__control_flow_mutations_parser.snap @@ -9,7 +9,72 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 376, + end: 381, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 376, + end: 381, + }, + kind: Line, + }, + Comment { + content: "// Test control flow constructs with variable and field mutations", + span: Span { + start: 376, + end: 381, + }, + kind: Line, + }, + Comment { + content: "// Per BT-90 design: literal blocks in control flow positions can mutate", + span: Span { + start: 376, + end: 381, + }, + kind: Line, + }, + Comment { + content: "// ========================================", + span: Span { + start: 376, + end: 381, + }, + kind: Line, + }, + Comment { + content: "// Local Variable Mutations", + span: Span { + start: 376, + end: 381, + }, + kind: Line, + }, + Comment { + content: "// ========================================", + span: Span { + start: 376, + end: 381, + }, + kind: Line, + }, + Comment { + content: "// Simple whileTrue with local variable mutation", + span: Span { + start: 376, + end: 381, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -174,7 +239,24 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Expected: count = 3", + span: Span { + start: 485, + end: 491, + }, + kind: Line, + }, + Comment { + content: "// whileFalse with mutation", + span: Span { + start: 485, + end: 491, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -339,7 +421,24 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Expected: count2 = 0", + span: Span { + start: 615, + end: 618, + }, + kind: Line, + }, + Comment { + content: "// Multiple variables mutated in one loop", + span: Span { + start: 615, + end: 618, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -666,7 +765,48 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Expected: sum = 6 (1+2+3), product = 6 (1*2*3), i = 4", + span: Span { + start: 948, + end: 955, + }, + kind: Line, + }, + Comment { + content: "// ========================================", + span: Span { + start: 948, + end: 955, + }, + kind: Line, + }, + Comment { + content: "// Control Flow with Index Variables", + span: Span { + start: 948, + end: 955, + }, + kind: Line, + }, + Comment { + content: "// ========================================", + span: Span { + start: 948, + end: 955, + }, + kind: Line, + }, + Comment { + content: "// timesRepeat with mutation", + span: Span { + start: 948, + end: 955, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -793,7 +933,24 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Expected: counter = 5", + span: Span { + start: 1066, + end: 1071, + }, + kind: Line, + }, + Comment { + content: "// to:do: with index and accumulator", + span: Span { + start: 1066, + end: 1071, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -944,7 +1101,48 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Expected: total = 55 (sum 1..10)", + span: Span { + start: 1314, + end: 1321, + }, + kind: Line, + }, + Comment { + content: "// ========================================", + span: Span { + start: 1314, + end: 1321, + }, + kind: Line, + }, + Comment { + content: "// Collection Iteration with Mutations", + span: Span { + start: 1314, + end: 1321, + }, + kind: Line, + }, + Comment { + content: "// ========================================", + span: Span { + start: 1314, + end: 1321, + }, + kind: Line, + }, + Comment { + content: "// Array do: with accumulation", + span: Span { + start: 1314, + end: 1321, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1153,7 +1351,24 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Expected: arraySum = 15", + span: Span { + start: 1491, + end: 1500, + }, + kind: Line, + }, + Comment { + content: "// collect: (returns new collection, but can mutate locals)", + span: Span { + start: 1491, + end: 1500, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1466,7 +1681,24 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Expected: evenCount = 2, doubled = #[2,4,6,8,10]", + span: Span { + start: 1703, + end: 1713, + }, + kind: Line, + }, + Comment { + content: "// select: with side effects", + span: Span { + start: 1703, + end: 1713, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1673,7 +1905,24 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Expected: matchCount = 5, evens = #[2,4]", + span: Span { + start: 1888, + end: 1895, + }, + kind: Line, + }, + Comment { + content: "// inject:into: with external mutation", + span: Span { + start: 1888, + end: 1895, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1928,7 +2177,48 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Expected: maxSeen = 5, finalSum = 15", + span: Span { + start: 2197, + end: 2205, + }, + kind: Line, + }, + Comment { + content: "// ========================================", + span: Span { + start: 2197, + end: 2205, + }, + kind: Line, + }, + Comment { + content: "// Nested Control Flow", + span: Span { + start: 2197, + end: 2205, + }, + kind: Line, + }, + Comment { + content: "// ========================================", + span: Span { + start: 2197, + end: 2205, + }, + kind: Line, + }, + Comment { + content: "// Nested loops with multiple mutations", + span: Span { + start: 2197, + end: 2205, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -2420,7 +2710,40 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Expected: innerSum = 6, outerSum = (2 + 4 + 6) = 12", + span: Span { + start: 2588, + end: 2595, + }, + kind: Line, + }, + Comment { + content: "// ========================================", + span: Span { + start: 2588, + end: 2595, + }, + kind: Line, + }, + Comment { + content: "// Field Mutations (Actor State)", + span: Span { + start: 2588, + end: 2595, + }, + kind: Line, + }, + Comment { + content: "// ========================================", + span: Span { + start: 2588, + end: 2595, + }, + kind: Line, + }, + ], trailing: None, }, expression: Error { @@ -3572,72 +3895,7 @@ Module { start: 376, end: 3742, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 376, - end: 381, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 376, - end: 381, - }, - kind: Line, - }, - Comment { - content: "// Test control flow constructs with variable and field mutations", - span: Span { - start: 376, - end: 381, - }, - kind: Line, - }, - Comment { - content: "// Per BT-90 design: literal blocks in control flow positions can mutate", - span: Span { - start: 376, - end: 381, - }, - kind: Line, - }, - Comment { - content: "// ========================================", - span: Span { - start: 376, - end: 381, - }, - kind: Line, - }, - Comment { - content: "// Local Variable Mutations", - span: Span { - start: 376, - end: 381, - }, - kind: Line, - }, - Comment { - content: "// ========================================", - span: Span { - start: 376, - end: 381, - }, - kind: Line, - }, - Comment { - content: "// Simple whileTrue with local variable mutation", - span: Span { - start: 376, - end: 381, - }, - kind: Line, - }, - ], + file_leading_comments: [], } Diagnostics: diff --git a/test-package-compiler/tests/snapshots/compiler_tests__empty_blocks_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__empty_blocks_parser.snap index 620bac16a..fd3cef970 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__empty_blocks_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__empty_blocks_parser.snap @@ -9,7 +9,48 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 175, + end: 180, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 175, + end: 180, + }, + kind: Line, + }, + Comment { + content: "// Test empty block edge case", + span: Span { + start: 175, + end: 180, + }, + kind: Line, + }, + Comment { + content: "// Blocks with no body or only whitespace", + span: Span { + start: 175, + end: 180, + }, + kind: Line, + }, + Comment { + content: "// Empty block - no expressions", + span: Span { + start: 175, + end: 180, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -40,7 +81,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Empty block with single space", + span: Span { + start: 221, + end: 235, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -71,7 +121,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Empty block with newlines", + span: Span { + start: 273, + end: 290, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -102,7 +161,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Empty block used as argument", + span: Span { + start: 332, + end: 342, + }, + kind: Line, + }, + ], trailing: None, }, expression: MessageSend { @@ -150,46 +218,5 @@ Module { start: 175, end: 349, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 175, - end: 180, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 175, - end: 180, - }, - kind: Line, - }, - Comment { - content: "// Test empty block edge case", - span: Span { - start: 175, - end: 180, - }, - kind: Line, - }, - Comment { - content: "// Blocks with no body or only whitespace", - span: Span { - start: 175, - end: 180, - }, - kind: Line, - }, - Comment { - content: "// Empty block - no expressions", - span: Span { - start: 175, - end: 180, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__empty_method_body_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__empty_method_body_parser.snap index 075e4acb4..d3a8604c0 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__empty_method_body_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__empty_method_body_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -208,46 +207,5 @@ Module { start: 244, end: 354, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 244, - end: 249, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 244, - end: 249, - }, - kind: Line, - }, - Comment { - content: "// Test empty method bodies (BT-859)", - span: Span { - start: 244, - end: 249, - }, - kind: Line, - }, - Comment { - content: "// Empty method bodies are a compile-time error.", - span: Span { - start: 244, - end: 249, - }, - kind: Line, - }, - Comment { - content: "// Developers must use `self notImplemented` or `self subclassResponsibility` instead.", - span: Span { - start: 244, - end: 249, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__error_message_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__error_message_parser.snap index 60e181322..c375496eb 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__error_message_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__error_message_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -240,40 +239,7 @@ Module { start: 186, end: 342, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 186, - end: 191, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 186, - end: 191, - }, - kind: Line, - }, - Comment { - content: "// Test error: message compilation", - span: Span { - start: 186, - end: 191, - }, - kind: Line, - }, - Comment { - content: "// The error: message should compile to erlang:error({beamtalk_error, Message})", - span: Span { - start: 186, - end: 191, - }, - kind: Line, - }, - ], + file_leading_comments: [], } Diagnostics: diff --git a/test-package-compiler/tests/snapshots/compiler_tests__error_recovery_invalid_syntax_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__error_recovery_invalid_syntax_parser.snap index 124224b5d..b57065627 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__error_recovery_invalid_syntax_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__error_recovery_invalid_syntax_parser.snap @@ -9,7 +9,48 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 179, + end: 180, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 179, + end: 180, + }, + kind: Line, + }, + Comment { + content: "// Test error recovery: invalid syntax", + span: Span { + start: 179, + end: 180, + }, + kind: Line, + }, + Comment { + content: "// Parser should create error nodes and continue", + span: Span { + start: 179, + end: 180, + }, + kind: Line, + }, + Comment { + content: "// Unexpected token", + span: Span { + start: 179, + end: 180, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -52,7 +93,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Missing operand", + span: Span { + start: 209, + end: 210, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -95,7 +145,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Malformed keyword message (missing part)", + span: Span { + start: 306, + end: 312, + }, + kind: Line, + }, + ], trailing: None, }, expression: Error { @@ -111,48 +170,7 @@ Module { start: 179, end: 372, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 179, - end: 180, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 179, - end: 180, - }, - kind: Line, - }, - Comment { - content: "// Test error recovery: invalid syntax", - span: Span { - start: 179, - end: 180, - }, - kind: Line, - }, - Comment { - content: "// Parser should create error nodes and continue", - span: Span { - start: 179, - end: 180, - }, - kind: Line, - }, - Comment { - content: "// Unexpected token", - span: Span { - start: 179, - end: 180, - }, - kind: Line, - }, - ], + file_leading_comments: [], } Diagnostics: diff --git a/test-package-compiler/tests/snapshots/compiler_tests__error_recovery_malformed_message_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__error_recovery_malformed_message_parser.snap index 168a9dcb3..f3a6dae2f 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__error_recovery_malformed_message_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__error_recovery_malformed_message_parser.snap @@ -9,7 +9,48 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 193, + end: 197, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 193, + end: 197, + }, + kind: Line, + }, + Comment { + content: "// Test error recovery: malformed message sends", + span: Span { + start: 193, + end: 197, + }, + kind: Line, + }, + Comment { + content: "// Parser should handle incomplete messages", + span: Span { + start: 193, + end: 197, + }, + kind: Line, + }, + Comment { + content: "// Incomplete keyword message", + span: Span { + start: 193, + end: 197, + }, + kind: Line, + }, + ], trailing: None, }, expression: MessageSend { @@ -53,7 +94,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Missing keyword part", + span: Span { + start: 231, + end: 236, + }, + kind: Line, + }, + ], trailing: None, }, expression: MessageSend { @@ -108,7 +158,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Extra keyword without argument", + span: Span { + start: 286, + end: 292, + }, + kind: Line, + }, + ], trailing: None, }, expression: MessageSend { @@ -181,7 +240,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Valid code after error", + span: Span { + start: 368, + end: 374, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -235,48 +303,7 @@ Module { start: 193, end: 383, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 193, - end: 197, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 193, - end: 197, - }, - kind: Line, - }, - Comment { - content: "// Test error recovery: malformed message sends", - span: Span { - start: 193, - end: 197, - }, - kind: Line, - }, - Comment { - content: "// Parser should handle incomplete messages", - span: Span { - start: 193, - end: 197, - }, - kind: Line, - }, - Comment { - content: "// Incomplete keyword message", - span: Span { - start: 193, - end: 197, - }, - kind: Line, - }, - ], + file_leading_comments: [], } Diagnostics: diff --git a/test-package-compiler/tests/snapshots/compiler_tests__error_recovery_unterminated_string_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__error_recovery_unterminated_string_parser.snap index a5d2291cf..30adbe6b0 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__error_recovery_unterminated_string_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__error_recovery_unterminated_string_parser.snap @@ -9,7 +9,48 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 188, + end: 192, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 188, + end: 192, + }, + kind: Line, + }, + Comment { + content: "// Test error recovery: unterminated string", + span: Span { + start: 188, + end: 192, + }, + kind: Line, + }, + Comment { + content: "// Lexer should recover and continue", + span: Span { + start: 188, + end: 192, + }, + kind: Line, + }, + Comment { + content: "// Unterminated double quote string", + span: Span { + start: 188, + end: 192, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -61,7 +102,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// More code", + span: Span { + start: 337, + end: 338, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -115,46 +165,5 @@ Module { start: 188, end: 347, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 188, - end: 192, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 188, - end: 192, - }, - kind: Line, - }, - Comment { - content: "// Test error recovery: unterminated string", - span: Span { - start: 188, - end: 192, - }, - kind: Line, - }, - Comment { - content: "// Lexer should recover and continue", - span: Span { - start: 188, - end: 192, - }, - kind: Line, - }, - Comment { - content: "// Unterminated double quote string", - span: Span { - start: 188, - end: 192, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__expect_directive_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__expect_directive_parser.snap index 8a7998b7a..974fa62ea 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__expect_directive_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__expect_directive_parser.snap @@ -9,7 +9,48 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 243, + end: 250, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 243, + end: 250, + }, + kind: Line, + }, + Comment { + content: "// Test @expect directive parsing — BT-782", + span: Span { + start: 243, + end: 250, + }, + kind: Line, + }, + Comment { + content: "// Verifies that @expect produces ExpectDirective AST nodes", + span: Span { + start: 243, + end: 250, + }, + kind: Line, + }, + Comment { + content: "// @expect dnu — suppress a DNU hint on the following expression", + span: Span { + start: 243, + end: 250, + }, + kind: Line, + }, + ], trailing: None, }, expression: ExpectDirective { @@ -48,7 +89,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// @expect type — suppress type mismatch warnings", + span: Span { + start: 326, + end: 333, + }, + kind: Line, + }, + ], trailing: None, }, expression: ExpectDirective { @@ -97,7 +147,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// @expect unused — suppress unused variable warnings", + span: Span { + start: 409, + end: 416, + }, + kind: Line, + }, + ], trailing: None, }, expression: ExpectDirective { @@ -140,7 +199,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// @expect all — suppress any diagnostic", + span: Span { + start: 482, + end: 489, + }, + kind: Line, + }, + ], trailing: None, }, expression: ExpectDirective { @@ -168,7 +236,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Multiple consecutive @expect directives stack on the same expression", + span: Span { + start: 587, + end: 594, + }, + kind: Line, + }, + ], trailing: None, }, expression: ExpectDirective { @@ -223,46 +300,5 @@ Module { start: 243, end: 629, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 243, - end: 250, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 243, - end: 250, - }, - kind: Line, - }, - Comment { - content: "// Test @expect directive parsing — BT-782", - span: Span { - start: 243, - end: 250, - }, - kind: Line, - }, - Comment { - content: "// Verifies that @expect produces ExpectDirective AST nodes", - span: Span { - start: 243, - end: 250, - }, - kind: Line, - }, - Comment { - content: "// @expect dnu — suppress a DNU hint on the following expression", - span: Span { - start: 243, - end: 250, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__future_pattern_matching_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__future_pattern_matching_parser.snap index d3c3b9791..82143cbbd 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__future_pattern_matching_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__future_pattern_matching_parser.snap @@ -9,7 +9,56 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 268, + end: 274, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 268, + end: 274, + }, + kind: Line, + }, + Comment { + content: "// Test future feature: pattern matching", + span: Span { + start: 268, + end: 274, + }, + kind: Line, + }, + Comment { + content: "// Match expressions with destructuring and guards", + span: Span { + start: 268, + end: 274, + }, + kind: Line, + }, + Comment { + content: "// NOTE: This feature is not yet implemented - test documents expected behavior", + span: Span { + start: 268, + end: 274, + }, + kind: Line, + }, + Comment { + content: "// Simple value matching", + span: Span { + start: 268, + end: 274, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -475,56 +524,7 @@ Module { start: 268, end: 2150, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 268, - end: 274, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 268, - end: 274, - }, - kind: Line, - }, - Comment { - content: "// Test future feature: pattern matching", - span: Span { - start: 268, - end: 274, - }, - kind: Line, - }, - Comment { - content: "// Match expressions with destructuring and guards", - span: Span { - start: 268, - end: 274, - }, - kind: Line, - }, - Comment { - content: "// NOTE: This feature is not yet implemented - test documents expected behavior", - span: Span { - start: 268, - end: 274, - }, - kind: Line, - }, - Comment { - content: "// Simple value matching", - span: Span { - start: 268, - end: 274, - }, - kind: Line, - }, - ], + file_leading_comments: [], } Diagnostics: diff --git a/test-package-compiler/tests/snapshots/compiler_tests__future_string_interpolation_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__future_string_interpolation_parser.snap index d349575d1..5316efd30 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__future_string_interpolation_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__future_string_interpolation_parser.snap @@ -9,7 +9,40 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 164, + end: 168, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 164, + end: 168, + }, + kind: Line, + }, + Comment { + content: "// Test string interpolation compilation (ADR 0023 Phase 3)", + span: Span { + start: 164, + end: 168, + }, + kind: Line, + }, + Comment { + content: "// Simple variable interpolation", + span: Span { + start: 164, + end: 168, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -85,7 +118,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Expression interpolation", + span: Span { + start: 238, + end: 241, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -182,7 +224,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Multiple interpolations in one string", + span: Span { + start: 342, + end: 351, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -299,7 +350,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Escape sequences in interpolated strings", + span: Span { + start: 469, + end: 476, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -342,7 +402,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Unicode in interpolated strings", + span: Span { + start: 562, + end: 570, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -432,7 +501,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Integer printString conversion", + span: Span { + start: 663, + end: 668, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -526,7 +604,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Adjacent interpolations", + span: Span { + start: 735, + end: 743, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -577,7 +664,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Only interpolation (no literal segments)", + span: Span { + start: 816, + end: 820, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -617,7 +713,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Plain string (no interpolation, zero overhead)", + span: Span { + start: 884, + end: 889, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -650,38 +755,5 @@ Module { start: 164, end: 908, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 164, - end: 168, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 164, - end: 168, - }, - kind: Line, - }, - Comment { - content: "// Test string interpolation compilation (ADR 0023 Phase 3)", - span: Span { - start: 164, - end: 168, - }, - kind: Line, - }, - Comment { - content: "// Simple variable interpolation", - span: Span { - start: 164, - end: 168, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__hello_world_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__hello_world_parser.snap index eda4b7cc9..32d7149c3 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__hello_world_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__hello_world_parser.snap @@ -9,7 +9,32 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 133, + end: 143, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 133, + end: 143, + }, + kind: Line, + }, + Comment { + content: "// Simple hello world program for testing compilation pipeline", + span: Span { + start: 133, + end: 143, + }, + kind: Line, + }, + ], trailing: None, }, expression: MessageSend { @@ -60,30 +85,5 @@ Module { start: 133, end: 165, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 133, - end: 143, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 133, - end: 143, - }, - kind: Line, - }, - Comment { - content: "// Simple hello world program for testing compilation pipeline", - span: Span { - start: 133, - end: 143, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__intrinsic_keyword_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__intrinsic_keyword_parser.snap index 99994de9c..44f7a15db 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__intrinsic_keyword_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__intrinsic_keyword_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -150,38 +149,5 @@ Module { start: 204, end: 290, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 204, - end: 210, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 204, - end: 210, - }, - kind: Line, - }, - Comment { - content: "// Test that @intrinsic produces identical codegen to @primitive (BT-484).", - span: Span { - start: 204, - end: 210, - }, - kind: Line, - }, - Comment { - content: "// Both keywords map to Expression::Primitive in the AST.", - span: Span { - start: 204, - end: 210, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__map_literals_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__map_literals_parser.snap index c6db22ebe..70d78f1a2 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__map_literals_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__map_literals_parser.snap @@ -9,7 +9,40 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 119, + end: 124, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 119, + end: 124, + }, + kind: Line, + }, + Comment { + content: "// Test map literal syntax parsing", + span: Span { + start: 119, + end: 124, + }, + kind: Line, + }, + Comment { + content: "// Empty map", + span: Span { + start: 119, + end: 124, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -37,7 +70,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Map with atom keys", + span: Span { + start: 155, + end: 161, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -114,7 +156,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Map with string keys", + span: Span { + start: 222, + end: 228, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -191,7 +242,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Map with integer keys", + span: Span { + start: 299, + end: 308, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -292,7 +352,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Map with mixed key types", + span: Span { + start: 386, + end: 391, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -393,7 +462,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Nested maps", + span: Span { + start: 461, + end: 465, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -564,7 +642,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Map with trailing comma", + span: Span { + start: 639, + end: 651, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -641,7 +728,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Single entry map", + span: Span { + start: 697, + end: 703, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -697,38 +793,5 @@ Module { start: 119, end: 726, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 119, - end: 124, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 119, - end: 124, - }, - kind: Line, - }, - Comment { - content: "// Test map literal syntax parsing", - span: Span { - start: 119, - end: 124, - }, - kind: Line, - }, - Comment { - content: "// Empty map", - span: Span { - start: 119, - end: 124, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__method_lookup_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__method_lookup_parser.snap index 843d8ca78..0f930a799 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__method_lookup_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__method_lookup_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -259,62 +258,5 @@ Module { start: 286, end: 534, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 286, - end: 292, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 286, - end: 292, - }, - kind: Line, - }, - Comment { - content: "// Compiler snapshot test for >> (method lookup) operator (BT-101, BT-323)", - span: Span { - start: 286, - end: 292, - }, - kind: Line, - }, - Comment { - content: "//", - span: Span { - start: 286, - end: 292, - }, - kind: Line, - }, - Comment { - content: "// Tests codegen for:", - span: Span { - start: 286, - end: 292, - }, - kind: Line, - }, - Comment { - content: "// - >> on class literal (compile-time optimized atom path)", - span: Span { - start: 286, - end: 292, - }, - kind: Line, - }, - Comment { - content: "// - >> on variable receiver (runtime resolution path)", - span: Span { - start: 286, - end: 292, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__multi_keyword_complex_args_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__multi_keyword_complex_args_parser.snap index 1540e7841..6e7d45ccd 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__multi_keyword_complex_args_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__multi_keyword_complex_args_parser.snap @@ -9,7 +9,48 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 189, + end: 194, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 189, + end: 194, + }, + kind: Line, + }, + Comment { + content: "// Test multi-keyword messages with complex arguments", + span: Span { + start: 189, + end: 194, + }, + kind: Line, + }, + Comment { + content: "// Each argument can be a complex expression", + span: Span { + start: 189, + end: 194, + }, + kind: Line, + }, + Comment { + content: "// Block arguments", + span: Span { + start: 189, + end: 194, + }, + kind: Line, + }, + ], trailing: None, }, expression: MessageSend { @@ -161,7 +202,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Binary operator arguments", + span: Span { + start: 262, + end: 272, + }, + kind: Line, + }, + ], trailing: None, }, expression: MessageSend { @@ -305,7 +355,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Mixed complexity", + span: Span { + start: 330, + end: 336, + }, + kind: Line, + }, + ], trailing: None, }, expression: MessageSend { @@ -423,7 +482,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Nested blocks and operators", + span: Span { + start: 431, + end: 440, + }, + kind: Line, + }, + ], trailing: None, }, expression: MessageSend { @@ -606,46 +674,5 @@ Module { start: 189, end: 520, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 189, - end: 194, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 189, - end: 194, - }, - kind: Line, - }, - Comment { - content: "// Test multi-keyword messages with complex arguments", - span: Span { - start: 189, - end: 194, - }, - kind: Line, - }, - Comment { - content: "// Each argument can be a complex expression", - span: Span { - start: 189, - end: 194, - }, - kind: Line, - }, - Comment { - content: "// Block arguments", - span: Span { - start: 189, - end: 194, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__nested_blocks_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__nested_blocks_parser.snap index 3b57ae8f7..5224c8f6f 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__nested_blocks_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__nested_blocks_parser.snap @@ -9,7 +9,48 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 158, + end: 168, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 158, + end: 168, + }, + kind: Line, + }, + Comment { + content: "// Test nested block closures", + span: Span { + start: 158, + end: 168, + }, + kind: Line, + }, + Comment { + content: "// Blocks inside other blocks", + span: Span { + start: 158, + end: 168, + }, + kind: Line, + }, + Comment { + content: "// Block returning a block", + span: Span { + start: 158, + end: 168, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -202,7 +243,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Deeply nested blocks", + span: Span { + start: 273, + end: 285, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -283,7 +333,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Block with nested block in body", + span: Span { + start: 334, + end: 349, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -443,7 +502,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Multiple nested blocks in arguments", + span: Span { + start: 447, + end: 456, + }, + kind: Line, + }, + ], trailing: None, }, expression: MessageSend { @@ -636,46 +704,5 @@ Module { start: 158, end: 542, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 158, - end: 168, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 158, - end: 168, - }, - kind: Line, - }, - Comment { - content: "// Test nested block closures", - span: Span { - start: 158, - end: 168, - }, - kind: Line, - }, - Comment { - content: "// Blocks inside other blocks", - span: Span { - start: 158, - end: 168, - }, - kind: Line, - }, - Comment { - content: "// Block returning a block", - span: Span { - start: 158, - end: 168, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__nested_keyword_messages_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__nested_keyword_messages_parser.snap index 33d63ab99..b992cb57b 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__nested_keyword_messages_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__nested_keyword_messages_parser.snap @@ -9,7 +9,48 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 196, + end: 200, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 196, + end: 200, + }, + kind: Line, + }, + Comment { + content: "// Test nested keyword message sends", + span: Span { + start: 196, + end: 200, + }, + kind: Line, + }, + Comment { + content: "// Keyword messages nested inside other keyword messages", + span: Span { + start: 196, + end: 200, + }, + kind: Line, + }, + Comment { + content: "// Nested in argument position", + span: Span { + start: 196, + end: 200, + }, + kind: Line, + }, + ], trailing: None, }, expression: MessageSend { @@ -139,7 +180,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Multiple levels of nesting", + span: Span { + start: 279, + end: 285, + }, + kind: Line, + }, + ], trailing: None, }, expression: MessageSend { @@ -269,7 +319,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Nested in receiver position", + span: Span { + start: 384, + end: 385, + }, + kind: Line, + }, + ], trailing: None, }, expression: MessageSend { @@ -348,7 +407,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Complex nesting with multiple keywords", + span: Span { + start: 463, + end: 469, + }, + kind: Line, + }, + ], trailing: None, }, expression: MessageSend { @@ -463,46 +531,5 @@ Module { start: 196, end: 524, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 196, - end: 200, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 196, - end: 200, - }, - kind: Line, - }, - Comment { - content: "// Test nested keyword message sends", - span: Span { - start: 196, - end: 200, - }, - kind: Line, - }, - Comment { - content: "// Keyword messages nested inside other keyword messages", - span: Span { - start: 196, - end: 200, - }, - kind: Line, - }, - Comment { - content: "// Nested in argument position", - span: Span { - start: 196, - end: 200, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__sealed_class_violation_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__sealed_class_violation_parser.snap index d9c95f178..294360563 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__sealed_class_violation_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__sealed_class_violation_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -138,38 +137,5 @@ Module { start: 179, end: 224, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 179, - end: 186, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 179, - end: 186, - }, - kind: Line, - }, - Comment { - content: "// Test that subclassing a sealed class produces a diagnostic error.", - span: Span { - start: 179, - end: 186, - }, - kind: Line, - }, - Comment { - content: "// Integer is a built-in sealed class.", - span: Span { - start: 179, - end: 186, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__sealed_method_override_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__sealed_method_override_parser.snap index d9752ce06..5590fb455 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__sealed_method_override_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__sealed_method_override_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -259,38 +258,5 @@ Module { start: 203, end: 333, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 203, - end: 209, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 203, - end: 209, - }, - kind: Line, - }, - Comment { - content: "// Test that overriding a sealed method produces a diagnostic error.", - span: Span { - start: 203, - end: 209, - }, - kind: Line, - }, - Comment { - content: "// Parent defines a sealed method, Child tries to override it.", - span: Span { - start: 203, - end: 209, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__stdlib_class_dictionary_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__stdlib_class_dictionary_parser.snap index 2dd11e3c6..248509ea0 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__stdlib_class_dictionary_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__stdlib_class_dictionary_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -624,46 +623,5 @@ Module { start: 247, end: 756, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 247, - end: 253, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 247, - end: 253, - }, - kind: Line, - }, - Comment { - content: "// Test Dictionary class compilation as a value type (not gen_server).", - span: Span { - start: 247, - end: 253, - }, - kind: Line, - }, - Comment { - content: "// Dictionary is a sealed Object subclass backed by Erlang maps.", - span: Span { - start: 247, - end: 253, - }, - kind: Line, - }, - Comment { - content: "// new/0 should return #{} (empty map).", - span: Span { - start: 247, - end: 253, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__stdlib_class_list_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__stdlib_class_list_parser.snap index d5b324112..1c9de2e09 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__stdlib_class_list_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__stdlib_class_list_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -2379,40 +2378,7 @@ Module { start: 208, end: 2049, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 208, - end: 214, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 208, - end: 214, - }, - kind: Line, - }, - Comment { - content: "// Test List class compilation as a value type (not gen_server).", - span: Span { - start: 208, - end: 214, - }, - kind: Line, - }, - Comment { - content: "// Mirrors lib/List.bt exactly — new/0 should return [] (empty list).", - span: Span { - start: 208, - end: 214, - }, - kind: Line, - }, - ], + file_leading_comments: [], } Diagnostics: diff --git a/test-package-compiler/tests/snapshots/compiler_tests__stdlib_class_set_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__stdlib_class_set_parser.snap index 5a0ef17b5..5badbfd2e 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__stdlib_class_set_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__stdlib_class_set_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -754,38 +753,5 @@ Module { start: 221, end: 905, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 221, - end: 227, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 221, - end: 227, - }, - kind: Line, - }, - Comment { - content: "// Test Set class compilation as a value type (not gen_server).", - span: Span { - start: 221, - end: 227, - }, - kind: Line, - }, - Comment { - content: "// Mirrors lib/Set.bt exactly — new/0 should return tagged map with empty elements.", - span: Span { - start: 221, - end: 227, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__stdlib_class_tuple_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__stdlib_class_tuple_parser.snap index 63685a875..0d8f999ad 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__stdlib_class_tuple_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__stdlib_class_tuple_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -455,46 +454,5 @@ Module { start: 240, end: 660, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 240, - end: 246, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 240, - end: 246, - }, - kind: Line, - }, - Comment { - content: "// Test Tuple class compilation as a value type (not gen_server).", - span: Span { - start: 240, - end: 246, - }, - kind: Line, - }, - Comment { - content: "// Tuple is a sealed Object subclass backed by Erlang tuples.", - span: Span { - start: 240, - end: 246, - }, - kind: Line, - }, - Comment { - content: "// new/0 should return {} (empty tuple).", - span: Span { - start: 240, - end: 246, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__string_operations_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__string_operations_parser.snap index 48e5fcd2d..499c4249f 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__string_operations_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__string_operations_parser.snap @@ -9,7 +9,40 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 177, + end: 185, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 177, + end: 185, + }, + kind: Line, + }, + Comment { + content: "// Test string operations - comprehensive coverage of string messages", + span: Span { + start: 177, + end: 185, + }, + kind: Line, + }, + Comment { + content: "// ===== String Concatenation =====", + span: Span { + start: 177, + end: 185, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -162,7 +195,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ===== String Length =====", + span: Span { + start: 286, + end: 289, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -203,7 +245,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ===== String Comparison =====", + span: Span { + start: 343, + end: 350, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -407,7 +458,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ===== String Case Transformation =====", + span: Span { + start: 508, + end: 513, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -489,7 +549,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ===== String Trimming =====", + span: Span { + start: 593, + end: 599, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -560,7 +629,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ===== String Empty/Non-Empty Checks =====", + span: Span { + start: 684, + end: 689, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -672,7 +750,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ===== String Character Access (1-based indexing) =====", + span: Span { + start: 813, + end: 822, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -790,7 +877,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ===== String Search Operations =====", + span: Span { + start: 908, + end: 913, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -908,7 +1004,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ===== String Prefix/Suffix Checks =====", + span: Span { + start: 1041, + end: 1047, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1026,7 +1131,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ===== String Splitting =====", + span: Span { + start: 1142, + end: 1145, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1115,7 +1229,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ===== String Reverse =====", + span: Span { + start: 1214, + end: 1222, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1159,38 +1282,5 @@ Module { start: 177, end: 1241, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 177, - end: 185, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 177, - end: 185, - }, - kind: Line, - }, - Comment { - content: "// Test string operations - comprehensive coverage of string messages", - span: Span { - start: 177, - end: 185, - }, - kind: Line, - }, - Comment { - content: "// ===== String Concatenation =====", - span: Span { - start: 177, - end: 185, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__typed_class_warnings_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__typed_class_warnings_parser.snap index bda91d6bf..6d278d295 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__typed_class_warnings_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__typed_class_warnings_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -503,56 +502,7 @@ Module { start: 275, end: 684, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 275, - end: 280, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 275, - end: 280, - }, - kind: Line, - }, - Comment { - content: "// Smoke test for typed class annotation warnings (BT-941).", - span: Span { - start: 275, - end: 280, - }, - kind: Line, - }, - Comment { - content: "//", - span: Span { - start: 275, - end: 280, - }, - kind: Line, - }, - Comment { - content: "// A `typed` class with deliberately incomplete annotations, so we can", - span: Span { - start: 275, - end: 280, - }, - kind: Line, - }, - Comment { - content: "// verify the type checker surfaces warnings for missing annotations.", - span: Span { - start: 275, - end: 280, - }, - kind: Line, - }, - ], + file_leading_comments: [], } Diagnostics: diff --git a/test-package-compiler/tests/snapshots/compiler_tests__typed_methods_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__typed_methods_parser.snap index 34cef0318..973164587 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__typed_methods_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__typed_methods_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -620,14 +619,5 @@ Module { start: 48, end: 531, }, - file_leading_comments: [ - Comment { - content: "// Typed method definitions for spec generation", - span: Span { - start: 48, - end: 53, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__typed_value_type_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__typed_value_type_parser.snap index 6680bc048..1d6d1f991 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__typed_value_type_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__typed_value_type_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -389,14 +388,5 @@ Module { start: 48, end: 378, }, - file_leading_comments: [ - Comment { - content: "// Typed value type methods for spec generation", - span: Span { - start: 48, - end: 54, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__unary_operators_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__unary_operators_parser.snap index 628a1d85c..e6a5a0c38 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__unary_operators_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__unary_operators_parser.snap @@ -9,8 +9,66 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 268, + end: 278, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 268, + end: 278, + }, + kind: Line, + }, + Comment { + content: "// Test all unary operators/messages for compilation verification", + span: Span { + start: 268, + end: 278, + }, + kind: Line, + }, + Comment { + content: "// Comprehensive coverage of unary operations supported in Core Erlang codegen", + span: Span { + start: 268, + end: 278, + }, + kind: Line, + }, + Comment { + content: "// ===== Integer Unary Operations =====", + span: Span { + start: 268, + end: 278, + }, + kind: Line, + }, + Comment { + content: "// Negation", + span: Span { + start: 268, + end: 278, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// Should generate: call \"erlang\":\"-\"(0, 5)", + span: Span { + start: 284, + end: 291, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -50,8 +108,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Absolute value", + span: Span { + start: 356, + end: 364, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// Should generate case expression for abs", + span: Span { + start: 374, + end: 377, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -97,7 +173,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Zero test", + span: Span { + start: 436, + end: 443, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -179,7 +264,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Even/Odd tests", + span: Span { + start: 496, + end: 505, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -261,7 +355,24 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ===== Boolean Unary Operations =====", + span: Span { + start: 594, + end: 601, + }, + kind: Line, + }, + Comment { + content: "// Logical NOT", + span: Span { + start: 594, + end: 601, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -343,7 +454,24 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ===== Complex Unary Expressions =====", + span: Span { + start: 704, + end: 711, + }, + kind: Line, + }, + Comment { + content: "// Chained unary messages", + span: Span { + start: 704, + end: 711, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -395,7 +523,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Unary in conditional with defined variable", + span: Span { + start: 776, + end: 783, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -551,7 +688,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Unary with block parameter", + span: Span { + start: 878, + end: 888, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -620,54 +766,5 @@ Module { start: 268, end: 908, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 268, - end: 278, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 268, - end: 278, - }, - kind: Line, - }, - Comment { - content: "// Test all unary operators/messages for compilation verification", - span: Span { - start: 268, - end: 278, - }, - kind: Line, - }, - Comment { - content: "// Comprehensive coverage of unary operations supported in Core Erlang codegen", - span: Span { - start: 268, - end: 278, - }, - kind: Line, - }, - Comment { - content: "// ===== Integer Unary Operations =====", - span: Span { - start: 268, - end: 278, - }, - kind: Line, - }, - Comment { - content: "// Negation", - span: Span { - start: 268, - end: 278, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__unicode_string_literals_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__unicode_string_literals_parser.snap index 02f175e21..7898186bc 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__unicode_string_literals_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__unicode_string_literals_parser.snap @@ -9,7 +9,40 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 180, + end: 184, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 180, + end: 184, + }, + kind: Line, + }, + Comment { + content: "// Test non-ASCII string literals encode correctly as UTF-8 bytes", + span: Span { + start: 180, + end: 184, + }, + kind: Line, + }, + Comment { + content: "// ===== Multi-byte UTF-8 Characters =====", + span: Span { + start: 180, + end: 184, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -99,7 +132,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ===== Mixed ASCII and Non-ASCII =====", + span: Span { + start: 278, + end: 283, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -132,38 +174,5 @@ Module { start: 180, end: 303, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 180, - end: 184, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 180, - end: 184, - }, - kind: Line, - }, - Comment { - content: "// Test non-ASCII string literals encode correctly as UTF-8 bytes", - span: Span { - start: 180, - end: 184, - }, - kind: Line, - }, - Comment { - content: "// ===== Multi-byte UTF-8 Characters =====", - span: Span { - start: 180, - end: 184, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__value_type_multi_expr_method_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__value_type_multi_expr_method_parser.snap index 1b860d08a..53b55fb2b 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__value_type_multi_expr_method_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__value_type_multi_expr_method_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -419,70 +418,5 @@ Module { start: 443, end: 708, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 443, - end: 449, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 443, - end: 449, - }, - kind: Line, - }, - Comment { - content: "// Compiler snapshot test for BT-367: multi-expression value-type method sequencing", - span: Span { - start: 443, - end: 449, - }, - kind: Line, - }, - Comment { - content: "//", - span: Span { - start: 443, - end: 449, - }, - kind: Line, - }, - Comment { - content: "// Verifies that value-type methods with multiple expressions generate", - span: Span { - start: 443, - end: 449, - }, - kind: Line, - }, - Comment { - content: "// correct Core Erlang using `let ... in` to sequence non-last expressions.", - span: Span { - start: 443, - end: 449, - }, - kind: Line, - }, - Comment { - content: "// The first expression (side-effecting) should be wrapped in a let binding,", - span: Span { - start: 443, - end: 449, - }, - kind: Line, - }, - Comment { - content: "// and only the last expression should be returned directly.", - span: Span { - start: 443, - end: 449, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__value_type_param_collision_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__value_type_param_collision_parser.snap index 75498e7c7..97c1523cf 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__value_type_param_collision_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__value_type_param_collision_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -258,70 +257,5 @@ Module { start: 445, end: 803, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 445, - end: 451, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 445, - end: 451, - }, - kind: Line, - }, - Comment { - content: "// Compiler snapshot test for BT-369: value-type temp var collision avoidance", - span: Span { - start: 445, - end: 451, - }, - kind: Line, - }, - Comment { - content: "//", - span: Span { - start: 445, - end: 451, - }, - kind: Line, - }, - Comment { - content: "// Verifies that method parameters with underscore-prefixed names (e.g., _seq0)", - span: Span { - start: 445, - end: 451, - }, - kind: Line, - }, - Comment { - content: "// don't collide with codegen-internal temp vars used for expression sequencing.", - span: Span { - start: 445, - end: 451, - }, - kind: Line, - }, - Comment { - content: "// Both parameter binding and sequencing temp vars go through the fresh_var", - span: Span { - start: 445, - end: 451, - }, - kind: Line, - }, - Comment { - content: "// counter, ensuring unique Core Erlang variable names.", - span: Span { - start: 445, - end: 451, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__while_true_simple_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__while_true_simple_parser.snap index e37d91d0e..46ea75070 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__while_true_simple_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__while_true_simple_parser.snap @@ -9,7 +9,32 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 125, + end: 129, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 125, + end: 129, + }, + kind: Line, + }, + Comment { + content: "// Simple whileTrue test with local variable mutation", + span: Span { + start: 125, + end: 129, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -227,7 +252,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Test without module-level field", + span: Span { + start: 250, + end: 259, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -445,7 +479,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Test mutating a block parameter (BT-142 PR review fix)", + span: Span { + start: 383, + end: 397, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -717,7 +760,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Test whileFalse with block parameter mutation (BT-142 PR review fix)", + span: Span { + start: 579, + end: 603, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -989,7 +1041,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Test timesRepeat: with mutation (BT-143)", + span: Span { + start: 759, + end: 774, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1169,7 +1230,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Test timesRepeat: with block parameter mutation (BT-143)", + span: Span { + start: 920, + end: 945, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1403,7 +1473,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Test to:do: with mutation (BT-143)", + span: Span { + start: 1089, + end: 1097, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1607,7 +1686,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Test to:do: with block parameter mutation (BT-143)", + span: Span { + start: 1232, + end: 1250, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1898,32 +1986,7 @@ Module { start: 125, end: 1379, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 125, - end: 129, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 125, - end: 129, - }, - kind: Line, - }, - Comment { - content: "// Simple whileTrue test with local variable mutation", - span: Span { - start: 125, - end: 129, - }, - kind: Line, - }, - ], + file_leading_comments: [], } Diagnostics: diff --git a/test-package-compiler/tests/snapshots/compiler_tests__whitespace_handling_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__whitespace_handling_parser.snap index 2cfc59035..c8932808d 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__whitespace_handling_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__whitespace_handling_parser.snap @@ -9,7 +9,48 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 155, + end: 156, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 155, + end: 156, + }, + kind: Line, + }, + Comment { + content: "// Test whitespace handling", + span: Span { + start: 155, + end: 156, + }, + kind: Line, + }, + Comment { + content: "// Whitespace should not affect parsing", + span: Span { + start: 155, + end: 156, + }, + kind: Line, + }, + Comment { + content: "// Extra spaces", + span: Span { + start: 155, + end: 156, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -60,7 +101,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Tabs and spaces mixed", + span: Span { + start: 202, + end: 203, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -111,7 +161,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Multiple newlines", + span: Span { + start: 238, + end: 244, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -162,7 +221,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Trailing whitespace (simulated)", + span: Span { + start: 291, + end: 292, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -192,7 +260,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Leading whitespace", + span: Span { + start: 330, + end: 342, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -222,7 +299,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Whitespace in message sends", + span: Span { + start: 381, + end: 387, + }, + kind: Line, + }, + ], trailing: None, }, expression: MessageSend { @@ -285,46 +371,5 @@ Module { start: 155, end: 428, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 155, - end: 156, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 155, - end: 156, - }, - kind: Line, - }, - Comment { - content: "// Test whitespace handling", - span: Span { - start: 155, - end: 156, - }, - kind: Line, - }, - Comment { - content: "// Whitespace should not affect parsing", - span: Span { - start: 155, - end: 156, - }, - kind: Line, - }, - Comment { - content: "// Extra spaces", - span: Span { - start: 155, - end: 156, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__workspace_binding_cascade_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__workspace_binding_cascade_parser.snap index f984b9ddf..78e06e0b7 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__workspace_binding_cascade_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__workspace_binding_cascade_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -180,22 +179,5 @@ Module { start: 130, end: 205, }, - file_leading_comments: [ - Comment { - content: "// BT-374: Workspace binding cascade dispatch.", - span: Span { - start: 130, - end: 135, - }, - kind: Line, - }, - Comment { - content: "// Cascade messages to a workspace binding should use persistent_term PID lookup.", - span: Span { - start: 130, - end: 135, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__workspace_binding_send_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__workspace_binding_send_parser.snap index 58ce50cd2..b71c2457c 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__workspace_binding_send_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__workspace_binding_send_parser.snap @@ -1,6 +1,5 @@ --- source: test-package-compiler/tests/compiler_tests.rs -assertion_line: 70 expression: output --- AST: @@ -134,22 +133,5 @@ Module { start: 148, end: 215, }, - file_leading_comments: [ - Comment { - content: "// BT-374: Workspace binding dispatch via persistent_term.", - span: Span { - start: 148, - end: 153, - }, - kind: Line, - }, - Comment { - content: "// Transcript is a workspace binding — generates persistent_term lookup + actor send.", - span: Span { - start: 148, - end: 153, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_array_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_array_parser.snap index 18fcbedb5..4207486cd 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_array_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_array_parser.snap @@ -9,7 +9,40 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 122, + end: 127, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 122, + end: 127, + }, + kind: Line, + }, + Comment { + content: "// Test Array (tuple) operations", + span: Span { + start: 122, + end: 127, + }, + kind: Line, + }, + Comment { + content: "// Array creation", + span: Span { + start: 122, + end: 127, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -232,40 +265,7 @@ Module { start: 122, end: 732, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 122, - end: 127, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 122, - end: 127, - }, - kind: Line, - }, - Comment { - content: "// Test Array (tuple) operations", - span: Span { - start: 122, - end: 127, - }, - kind: Line, - }, - Comment { - content: "// Array creation", - span: Span { - start: 122, - end: 127, - }, - kind: Line, - }, - ], + file_leading_comments: [], } Diagnostics: diff --git a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_block_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_block_parser.snap index c1aa00da6..edffaf9fd 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_block_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_block_parser.snap @@ -9,7 +9,40 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 140, + end: 145, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 140, + end: 145, + }, + kind: Line, + }, + Comment { + content: "// Test block evaluation and control flow", + span: Span { + start: 140, + end: 145, + }, + kind: Line, + }, + Comment { + content: "// Simple block evaluation", + span: Span { + start: 140, + end: 145, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -97,7 +130,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Block with one argument", + span: Span { + start: 204, + end: 213, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -232,7 +274,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Block with two arguments", + span: Span { + start: 289, + end: 292, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -390,7 +441,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// While loop", + span: Span { + start: 360, + end: 367, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -555,7 +615,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Block captures variables", + span: Span { + start: 452, + end: 457, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -697,38 +766,5 @@ Module { start: 140, end: 521, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 140, - end: 145, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 140, - end: 145, - }, - kind: Line, - }, - Comment { - content: "// Test block evaluation and control flow", - span: Span { - start: 140, - end: 145, - }, - kind: Line, - }, - Comment { - content: "// Simple block evaluation", - span: Span { - start: 140, - end: 145, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_boolean_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_boolean_parser.snap index 876ded03f..a389d2506 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_boolean_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_boolean_parser.snap @@ -9,7 +9,40 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 154, + end: 158, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 154, + end: 158, + }, + kind: Line, + }, + Comment { + content: "// Test boolean control flow with True and False", + span: Span { + start: 154, + end: 158, + }, + kind: Line, + }, + Comment { + content: "// Test ifTrue:ifFalse: with true", + span: Span { + start: 154, + end: 158, + }, + kind: Line, + }, + ], trailing: None, }, expression: MessageSend { @@ -169,7 +202,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Test ifTrue:ifFalse: with false", + span: Span { + start: 261, + end: 266, + }, + kind: Line, + }, + ], trailing: None, }, expression: MessageSend { @@ -329,7 +371,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Test logical AND", + span: Span { + start: 354, + end: 361, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -557,7 +608,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Test logical OR", + span: Span { + start: 460, + end: 467, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -785,7 +845,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Test logical NOT", + span: Span { + start: 566, + end: 573, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -870,38 +939,5 @@ Module { start: 154, end: 606, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 154, - end: 158, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 154, - end: 158, - }, - kind: Line, - }, - Comment { - content: "// Test boolean control flow with True and False", - span: Span { - start: 154, - end: 158, - }, - kind: Line, - }, - Comment { - content: "// Test ifTrue:ifFalse: with true", - span: Span { - start: 154, - end: 158, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_dictionary_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_dictionary_parser.snap index 5a9143189..8a4213266 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_dictionary_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_dictionary_parser.snap @@ -9,7 +9,40 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 140, + end: 146, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 140, + end: 146, + }, + kind: Line, + }, + Comment { + content: "// Test Dictionary (key-value map) operations", + span: Span { + start: 140, + end: 146, + }, + kind: Line, + }, + Comment { + content: "// Dictionary creation", + span: Span { + start: 140, + end: 146, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -138,7 +171,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Key access", + span: Span { + start: 226, + end: 230, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -256,7 +298,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Safe access with default", + span: Span { + start: 303, + end: 308, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -348,7 +399,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Update (returns new dictionary)", + span: Span { + start: 388, + end: 393, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -423,7 +483,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Add new key", + span: Span { + start: 437, + end: 444, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -498,7 +567,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Size", + span: Span { + start: 489, + end: 493, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -539,7 +617,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Key test", + span: Span { + start: 522, + end: 529, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -657,7 +744,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Remove key", + span: Span { + start: 609, + end: 616, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -716,7 +812,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Get keys and values", + span: Span { + start: 668, + end: 672, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -798,7 +903,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Iteration over keys and values", + span: Span { + start: 747, + end: 753, + }, + kind: Line, + }, + ], trailing: None, }, expression: MessageSend { @@ -955,7 +1069,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Transformation of values", + span: Span { + start: 853, + end: 860, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1107,7 +1230,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Merge two dictionaries", + span: Span { + start: 935, + end: 939, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1323,38 +1455,5 @@ Module { start: 140, end: 1019, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 140, - end: 146, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 140, - end: 146, - }, - kind: Line, - }, - Comment { - content: "// Test Dictionary (key-value map) operations", - span: Span { - start: 140, - end: 146, - }, - kind: Line, - }, - Comment { - content: "// Dictionary creation", - span: Span { - start: 140, - end: 146, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_integer_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_integer_parser.snap index a3e000a52..c6032cd35 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_integer_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_integer_parser.snap @@ -9,7 +9,40 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 133, + end: 136, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 133, + end: 136, + }, + kind: Line, + }, + Comment { + content: "// Test integer arithmetic and operations", + span: Span { + start: 133, + end: 136, + }, + kind: Line, + }, + Comment { + content: "// Basic arithmetic", + span: Span { + start: 133, + end: 136, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -213,8 +246,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Integer division and modulo", + span: Span { + start: 235, + end: 241, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// 5", + span: Span { + start: 245, + end: 247, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -294,7 +345,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Comparison", + span: Span { + start: 288, + end: 294, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -447,7 +507,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Iteration - times repeat", + span: Span { + start: 370, + end: 377, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -574,7 +643,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Range iteration", + span: Span { + start: 443, + end: 446, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -725,7 +803,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Number tests", + span: Span { + start: 504, + end: 510, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -848,7 +935,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Custom step iteration - positive step (odd numbers)", + span: Span { + start: 615, + end: 621, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1015,7 +1111,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Custom step iteration - negative step (countdown)", + span: Span { + start: 728, + end: 737, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -1185,38 +1290,5 @@ Module { start: 133, end: 796, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 133, - end: 136, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 133, - end: 136, - }, - kind: Line, - }, - Comment { - content: "// Test integer arithmetic and operations", - span: Span { - start: 133, - end: 136, - }, - kind: Line, - }, - Comment { - content: "// Basic arithmetic", - span: Span { - start: 133, - end: 136, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_list_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_list_parser.snap index 19716a9de..d9d32147e 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_list_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_list_parser.snap @@ -9,7 +9,40 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 126, + end: 133, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 126, + end: 133, + }, + kind: Line, + }, + Comment { + content: "// Test List (linked list) operations", + span: Span { + start: 126, + end: 133, + }, + kind: Line, + }, + Comment { + content: "// List creation", + span: Span { + start: 126, + end: 133, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -227,40 +260,7 @@ Module { start: 126, end: 838, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 126, - end: 133, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 126, - end: 133, - }, - kind: Line, - }, - Comment { - content: "// Test List (linked list) operations", - span: Span { - start: 126, - end: 133, - }, - kind: Line, - }, - Comment { - content: "// List creation", - span: Span { - start: 126, - end: 133, - }, - kind: Line, - }, - ], + file_leading_comments: [], } Diagnostics: diff --git a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_nil_object_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_nil_object_parser.snap index 2b5d52a2a..ba1642339 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_nil_object_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_nil_object_parser.snap @@ -9,8 +9,74 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 653, + end: 660, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 653, + end: 660, + }, + kind: Line, + }, + Comment { + content: "// Test non-nil objects' nil-testing protocol (inherited from Actor)", + span: Span { + start: 653, + end: 660, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 653, + end: 660, + }, + kind: Line, + }, + Comment { + content: "// Basic Testing Methods (Non-Nil Objects)", + span: Span { + start: 653, + end: 660, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 653, + end: 660, + }, + kind: Line, + }, + Comment { + content: "// Test isNil / notNil on integers", + span: Span { + start: 653, + end: 660, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => false", + span: Span { + start: 667, + end: 672, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -51,7 +117,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => true", + span: Span { + start: 705, + end: 711, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -92,7 +167,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => false (zero is not nil!)", + span: Span { + start: 741, + end: 746, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -132,8 +216,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Test isNil / notNil on strings", + span: Span { + start: 820, + end: 827, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => false", + span: Span { + start: 839, + end: 844, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -174,7 +276,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => true", + span: Span { + start: 878, + end: 884, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -215,7 +326,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => false (empty string is not nil!)", + span: Span { + start: 911, + end: 916, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -255,8 +375,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Test isNil / notNil on booleans", + span: Span { + start: 999, + end: 1006, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => false", + span: Span { + start: 1015, + end: 1020, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -297,7 +435,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => true", + span: Span { + start: 1054, + end: 1060, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -338,7 +485,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => false (false is not nil!)", + span: Span { + start: 1093, + end: 1098, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -379,7 +535,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => true", + span: Span { + start: 1153, + end: 1159, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -419,8 +584,50 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 1704, + end: 1712, + }, + kind: Line, + }, + Comment { + content: "// Control Flow Methods (Non-Nil Objects)", + span: Span { + start: 1704, + end: 1712, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 1704, + end: 1712, + }, + kind: Line, + }, + Comment { + content: "// Test ifNil: returns self without evaluating block", + span: Span { + start: 1704, + end: 1712, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => 42", + span: Span { + start: 1736, + end: 1737, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -495,8 +702,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Test ifNotNil: evaluates block with receiver as argument", + span: Span { + start: 1809, + end: 1817, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => 43", + span: Span { + start: 1849, + end: 1850, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -600,8 +825,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Test ifNil:ifNotNil: evaluates notNilBlock with receiver", + span: Span { + start: 1922, + end: 1930, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => \"HELLO\"", + span: Span { + start: 1992, + end: 1993, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -728,8 +971,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Test ifNotNil:ifNil: (reversed order) evaluates notNilBlock with receiver", + span: Span { + start: 2087, + end: 2095, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => 20", + span: Span { + start: 2138, + end: 2139, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -866,8 +1127,50 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 2675, + end: 2683, + }, + kind: Line, + }, + Comment { + content: "// Edge Cases: Block Receives Receiver", + span: Span { + start: 2675, + end: 2683, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 2675, + end: 2683, + }, + kind: Line, + }, + Comment { + content: "// Verify block receives the receiver as argument", + span: Span { + start: 2675, + end: 2683, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => 150", + span: Span { + start: 2713, + end: 2714, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -972,7 +1275,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => 4", + span: Span { + start: 2771, + end: 2772, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1066,8 +1378,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Multiple operations on the passed value", + span: Span { + start: 2826, + end: 2834, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => 13", + span: Span { + start: 2867, + end: 2868, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1198,8 +1528,50 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 3408, + end: 3416, + }, + kind: Line, + }, + Comment { + content: "// Edge Cases: Chaining and Composition", + span: Span { + start: 3408, + end: 3416, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 3408, + end: 3416, + }, + kind: Line, + }, + Comment { + content: "// Chaining: ifNotNil: result in further computation", + span: Span { + start: 3408, + end: 3416, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => 94", + span: Span { + start: 3450, + end: 3452, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1330,8 +1702,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Nested ifNotNil: - both evaluate", + span: Span { + start: 3500, + end: 3508, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => 15", + span: Span { + start: 3571, + end: 3572, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1489,8 +1879,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// ifNil: on non-nil returns self, can chain", + span: Span { + start: 3629, + end: 3637, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => 150", + span: Span { + start: 3660, + end: 3662, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1592,8 +2000,50 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 4190, + end: 4198, + }, + kind: Line, + }, + Comment { + content: "// Edge Cases: Boolean Logic Integration", + span: Span { + start: 4190, + end: 4198, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 4190, + end: 4198, + }, + kind: Line, + }, + Comment { + content: "// Combining notNil with boolean logic", + span: Span { + start: 4190, + end: 4198, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => true", + span: Span { + start: 4222, + end: 4223, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1680,7 +2130,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => false", + span: Span { + start: 4272, + end: 4273, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1766,8 +2225,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Using notNil result in ifTrue:ifFalse:", + span: Span { + start: 4330, + end: 4338, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => \"is not nil\"", + span: Span { + start: 4394, + end: 4395, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1886,8 +2363,50 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 4912, + end: 4920, + }, + kind: Line, + }, + Comment { + content: "// Edge Cases: Different Object Types", + span: Span { + start: 4912, + end: 4920, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 4912, + end: 4920, + }, + kind: Line, + }, + Comment { + content: "// Blocks are not nil", + span: Span { + start: 4912, + end: 4920, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => false", + span: Span { + start: 4929, + end: 4934, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1945,7 +2464,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => false", + span: Span { + start: 4974, + end: 4979, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -2010,8 +2538,50 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 5547, + end: 5555, + }, + kind: Line, + }, + Comment { + content: "// Edge Cases: ifNil: Should NOT Evaluate Block", + span: Span { + start: 5547, + end: 5555, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 5547, + end: 5555, + }, + kind: Line, + }, + Comment { + content: "// Verify ifNil: doesn't evaluate by checking return equals receiver", + span: Span { + start: 5547, + end: 5555, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => true", + span: Span { + start: 5582, + end: 5584, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -2113,8 +2683,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// ifNil: with complex block expression (should not evaluate)", + span: Span { + start: 5660, + end: 5668, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => 10 (not 7)", + span: Span { + start: 5692, + end: 5693, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -2231,7 +2819,40 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 6236, + end: 6241, + }, + kind: Line, + }, + Comment { + content: "// Edge Cases: Mixed nil and non-nil in Expressions", + span: Span { + start: 6236, + end: 6241, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 6236, + end: 6241, + }, + kind: Line, + }, + Comment { + content: "// Assign value based on isNil test", + span: Span { + start: 6236, + end: 6241, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -2262,7 +2883,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => 42", + span: Span { + start: 6299, + end: 6300, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -2381,7 +3011,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Use ifNotNil: to safely transform", + span: Span { + start: 6349, + end: 6355, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -2412,7 +3051,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => 30", + span: Span { + start: 6402, + end: 6403, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -2516,8 +3164,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Compare with nil's behavior (for contrast)", + span: Span { + start: 6461, + end: 6469, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => \"nil case\"", + span: Span { + start: 6527, + end: 6528, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -2634,7 +3300,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => \"not nil case\"", + span: Span { + start: 6612, + end: 6613, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -2750,8 +3425,50 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 7148, + end: 7156, + }, + kind: Line, + }, + Comment { + content: "// Edge Cases: Return Value Verification", + span: Span { + start: 7148, + end: 7156, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 7148, + end: 7156, + }, + kind: Line, + }, + Comment { + content: "// ifNotNil: returns block result", + span: Span { + start: 7148, + end: 7156, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => true", + span: Span { + start: 7192, + end: 7194, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -2882,8 +3599,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// ifNil: returns self unchanged", + span: Span { + start: 7241, + end: 7249, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => true", + span: Span { + start: 7274, + end: 7277, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -2985,7 +3720,40 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 7793, + end: 7801, + }, + kind: Line, + }, + Comment { + content: "// Real-World Usage Patterns", + span: Span { + start: 7793, + end: 7801, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 7793, + end: 7801, + }, + kind: Line, + }, + Comment { + content: "// Safe access pattern with ifNotNil:", + span: Span { + start: 7793, + end: 7801, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -3016,7 +3784,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => \"Hello, Alice!\"", + span: Span { + start: 7875, + end: 7876, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -3141,7 +3918,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Default value pattern with ifNil:", + span: Span { + start: 7938, + end: 7947, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -3172,7 +3958,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => 42", + span: Span { + start: 7991, + end: 7992, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -3247,7 +4042,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Transformation with default pattern", + span: Span { + start: 8043, + end: 8054, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -3278,7 +4082,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => 14", + span: Span { + start: 8115, + end: 8116, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -3418,62 +4231,5 @@ Module { start: 653, end: 8116, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 653, - end: 660, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 653, - end: 660, - }, - kind: Line, - }, - Comment { - content: "// Test non-nil objects' nil-testing protocol (inherited from Actor)", - span: Span { - start: 653, - end: 660, - }, - kind: Line, - }, - Comment { - content: "// ═══════════════════════════════════════════════════════════════════════", - span: Span { - start: 653, - end: 660, - }, - kind: Line, - }, - Comment { - content: "// Basic Testing Methods (Non-Nil Objects)", - span: Span { - start: 653, - end: 660, - }, - kind: Line, - }, - Comment { - content: "// ═══════════════════════════════════════════════════════════════════════", - span: Span { - start: 653, - end: 660, - }, - kind: Line, - }, - Comment { - content: "// Test isNil / notNil on integers", - span: Span { - start: 653, - end: 660, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_nil_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_nil_parser.snap index 1bfbb1dfd..d3990f582 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_nil_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_nil_parser.snap @@ -9,8 +9,74 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 600, + end: 607, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 600, + end: 607, + }, + kind: Line, + }, + Comment { + content: "// Test Nil control flow and testing messages", + span: Span { + start: 600, + end: 607, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 600, + end: 607, + }, + kind: Line, + }, + Comment { + content: "// Basic Testing Methods", + span: Span { + start: 600, + end: 607, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 600, + end: 607, + }, + kind: Line, + }, + Comment { + content: "// Test isNil / notNil", + span: Span { + start: 600, + end: 607, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => true", + span: Span { + start: 615, + end: 620, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -51,7 +117,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => false", + span: Span { + start: 653, + end: 659, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -91,7 +166,40 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 1172, + end: 1179, + }, + kind: Line, + }, + Comment { + content: "// Control Flow Methods", + span: Span { + start: 1172, + end: 1179, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 1172, + end: 1179, + }, + kind: Line, + }, + Comment { + content: "// Test ifNil: evaluates the block", + span: Span { + start: 1172, + end: 1179, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -167,7 +275,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Test ifNotNil: returns nil (block not evaluated)", + span: Span { + start: 1259, + end: 1266, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -272,7 +389,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Test ifNil:ifNotNil: evaluates nilBlock", + span: Span { + start: 1345, + end: 1352, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -389,7 +515,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Test ifNotNil:ifNil: (reversed order) evaluates nilBlock", + span: Span { + start: 1473, + end: 1480, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -506,7 +641,40 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 2055, + end: 2062, + }, + kind: Line, + }, + Comment { + content: "// Copy Operations (Singleton)", + span: Span { + start: 2055, + end: 2062, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 2055, + end: 2062, + }, + kind: Line, + }, + Comment { + content: "// Test copy operations return self (singleton)", + span: Span { + start: 2055, + end: 2062, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -629,8 +797,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Test printString", + span: Span { + start: 2147, + end: 2155, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => \"nil\"", + span: Span { + start: 2163, + end: 2174, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -670,8 +856,50 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 2719, + end: 2727, + }, + kind: Line, + }, + Comment { + content: "// Edge Cases: Chaining and Composition", + span: Span { + start: 2719, + end: 2727, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 2719, + end: 2727, + }, + kind: Line, + }, + Comment { + content: "// Chaining: use ifNil: result in further computation", + span: Span { + start: 2719, + end: 2727, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => 15", + span: Span { + start: 2751, + end: 2752, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -773,8 +1001,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Chaining: ifNil: with message send on result", + span: Span { + start: 2812, + end: 2820, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => \"HELLO\"", + span: Span { + start: 2847, + end: 2856, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -866,8 +1112,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Nested ifNil: - outer nil, inner returns value from block", + span: Span { + start: 2934, + end: 2942, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => \"nested default\"", + span: Span { + start: 2987, + end: 2988, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -988,8 +1252,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Block that itself returns nil", + span: Span { + start: 3047, + end: 3055, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => nil", + span: Span { + start: 3074, + end: 3075, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1064,8 +1346,50 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 3588, + end: 3596, + }, + kind: Line, + }, + Comment { + content: "// Edge Cases: Equality and Identity", + span: Span { + start: 3588, + end: 3596, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 3588, + end: 3596, + }, + kind: Line, + }, + Comment { + content: "// nil equality with itself", + span: Span { + start: 3588, + end: 3596, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => true", + span: Span { + start: 3608, + end: 3611, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1115,8 +1439,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// nil inequality with other values", + span: Span { + start: 3661, + end: 3669, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => false", + span: Span { + start: 3681, + end: 3682, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1167,7 +1509,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => false", + span: Span { + start: 3718, + end: 3720, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1218,7 +1569,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => false (nil is not false!)", + span: Span { + start: 3755, + end: 3760, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1268,8 +1628,50 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 4309, + end: 4317, + }, + kind: Line, + }, + Comment { + content: "// Edge Cases: Boolean Logic Integration", + span: Span { + start: 4309, + end: 4317, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 4309, + end: 4317, + }, + kind: Line, + }, + Comment { + content: "// Combining isNil with boolean logic", + span: Span { + start: 4309, + end: 4317, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => true", + span: Span { + start: 4341, + end: 4342, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1356,7 +1758,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => true (short-circuits)", + span: Span { + start: 4388, + end: 4389, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1443,7 +1854,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => false (short-circuits)", + span: Span { + start: 4453, + end: 4454, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1530,7 +1950,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => true", + span: Span { + start: 4517, + end: 4518, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1616,8 +2045,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Using isNil result in ifTrue:ifFalse:", + span: Span { + start: 4574, + end: 4582, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => \"is nil\"", + span: Span { + start: 4634, + end: 4635, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1736,8 +2183,50 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 5156, + end: 5164, + }, + kind: Line, + }, + Comment { + content: "// Edge Cases: Block Expressions", + span: Span { + start: 5156, + end: 5164, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 5156, + end: 5164, + }, + kind: Line, + }, + Comment { + content: "// ifNil: with arithmetic in block", + span: Span { + start: 5156, + end: 5164, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => 7", + span: Span { + start: 5189, + end: 5190, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1854,8 +2343,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// ifNotNil: block should NOT be evaluated", + span: Span { + start: 5244, + end: 5252, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => nil (block not evaluated)", + span: Span { + start: 5291, + end: 5292, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -1980,7 +2487,40 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 5871, + end: 5877, + }, + kind: Line, + }, + Comment { + content: "// Edge Cases: Multiple Consecutive Checks ", + span: Span { + start: 5871, + end: 5877, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 5871, + end: 5877, + }, + kind: Line, + }, + Comment { + content: "// Multiple isNil checks in sequence (should all be consistent)", + span: Span { + start: 5871, + end: 5877, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -2104,7 +2644,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => true", + span: Span { + start: 5978, + end: 5979, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -2225,7 +2774,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Assigning nil and then checking", + span: Span { + start: 6028, + end: 6038, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -2256,7 +2814,16 @@ Module { ExpressionStatement { comments: CommentAttachment { leading: [], - trailing: None, + trailing: Some( + Comment { + content: "// => true", + span: Span { + start: 6069, + end: 6074, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -2296,8 +2863,50 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 6612, + end: 6620, + }, + kind: Line, + }, + Comment { + content: "// Edge Cases: ifNil: vs ifNotNil: Return Values", + span: Span { + start: 6612, + end: 6620, + }, + kind: Line, + }, + Comment { + content: "// ═══════════════════════════════════════════════════════════════════════", + span: Span { + start: 6612, + end: 6620, + }, + kind: Line, + }, + Comment { + content: "// ifNil: returns block result, not nil", + span: Span { + start: 6612, + end: 6620, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => 42 (not nil)", + span: Span { + start: 6638, + end: 6639, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -2372,8 +2981,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// ifNotNil: on nil returns nil itself", + span: Span { + start: 6700, + end: 6708, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => nil (block not evaluated)", + span: Span { + start: 6729, + end: 6730, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -2448,8 +3075,26 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], - trailing: None, + leading: [ + Comment { + content: "// Verify ifNotNil: truly doesn't evaluate by checking return is nil", + span: Span { + start: 6834, + end: 6842, + }, + kind: Line, + }, + ], + trailing: Some( + Comment { + content: "// => true", + span: Span { + start: 6869, + end: 6874, + }, + kind: Line, + }, + ), }, expression: Assignment { target: Identifier( @@ -2544,62 +3189,5 @@ Module { start: 600, end: 6874, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 600, - end: 607, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 600, - end: 607, - }, - kind: Line, - }, - Comment { - content: "// Test Nil control flow and testing messages", - span: Span { - start: 600, - end: 607, - }, - kind: Line, - }, - Comment { - content: "// ═══════════════════════════════════════════════════════════════════════", - span: Span { - start: 600, - end: 607, - }, - kind: Line, - }, - Comment { - content: "// Basic Testing Methods", - span: Span { - start: 600, - end: 607, - }, - kind: Line, - }, - Comment { - content: "// ═══════════════════════════════════════════════════════════════════════", - span: Span { - start: 600, - end: 607, - }, - kind: Line, - }, - Comment { - content: "// Test isNil / notNil", - span: Span { - start: 600, - end: 607, - }, - kind: Line, - }, - ], + file_leading_comments: [], } diff --git a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_set_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_set_parser.snap index 97033f05b..51e3f01b8 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_set_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_set_parser.snap @@ -9,7 +9,40 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 138, + end: 144, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 138, + end: 144, + }, + kind: Line, + }, + Comment { + content: "// Test Set (unique elements) operations", + span: Span { + start: 138, + end: 144, + }, + kind: Line, + }, + Comment { + content: "// Set creation from list", + span: Span { + start: 138, + end: 144, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -170,40 +203,7 @@ Module { start: 138, end: 918, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 138, - end: 144, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 138, - end: 144, - }, - kind: Line, - }, - Comment { - content: "// Test Set (unique elements) operations", - span: Span { - start: 138, - end: 144, - }, - kind: Line, - }, - Comment { - content: "// Set creation from list", - span: Span { - start: 138, - end: 144, - }, - kind: Line, - }, - ], + file_leading_comments: [], } Diagnostics: diff --git a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_string_parser.snap b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_string_parser.snap index 0bc560b2e..bf80b48a7 100644 --- a/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_string_parser.snap +++ b/test-package-compiler/tests/snapshots/compiler_tests__ws_stdlib_string_parser.snap @@ -9,7 +9,40 @@ Module { expressions: [ ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Copyright 2026 James Casey", + span: Span { + start: 116, + end: 124, + }, + kind: Line, + }, + Comment { + content: "// SPDX-License-Identifier: Apache-2.0", + span: Span { + start: 116, + end: 124, + }, + kind: Line, + }, + Comment { + content: "// Test string operations", + span: Span { + start: 116, + end: 124, + }, + kind: Line, + }, + Comment { + content: "// String literals", + span: Span { + start: 116, + end: 124, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -69,7 +102,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// Concatenation", + span: Span { + start: 170, + end: 177, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -162,7 +204,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// String length", + span: Span { + start: 231, + end: 234, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -203,7 +254,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// String comparison", + span: Span { + start: 276, + end: 283, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -305,7 +365,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// String transformation", + span: Span { + start: 362, + end: 367, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -387,7 +456,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// String testing", + span: Span { + start: 434, + end: 441, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -469,7 +547,16 @@ Module { }, ExpressionStatement { comments: CommentAttachment { - leading: [], + leading: [ + Comment { + content: "// String searching", + span: Span { + start: 510, + end: 515, + }, + kind: Line, + }, + ], trailing: None, }, expression: Assignment { @@ -590,38 +677,5 @@ Module { start: 116, end: 591, }, - file_leading_comments: [ - Comment { - content: "// Copyright 2026 James Casey", - span: Span { - start: 116, - end: 124, - }, - kind: Line, - }, - Comment { - content: "// SPDX-License-Identifier: Apache-2.0", - span: Span { - start: 116, - end: 124, - }, - kind: Line, - }, - Comment { - content: "// Test string operations", - span: Span { - start: 116, - end: 124, - }, - kind: Line, - }, - Comment { - content: "// String literals", - span: Span { - start: 116, - end: 124, - }, - kind: Line, - }, - ], + file_leading_comments: [], } From 58b0cf60d3861c55772dc36c901c45e58927227d Mon Sep 17 00:00:00 2001 From: James Casey Date: Sat, 28 Feb 2026 20:51:49 +0000 Subject: [PATCH 2/2] fix: address CodeRabbit review comments BT-976 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Guard collect_trailing_comment() with progress check in parse_module(), parse_method_body(), and parse_block() — avoids attaching stale trailing trivia when parse_expression() consumes no tokens - Fix leading comment attachment for standalone method definitions: parse_standalone_method_definition() now calls collect_comment_attachment() on the class-name token before advancing, and prepends those comments to the parsed method's comments.leading (previously they were dropped because parse_identifier() consumed the token without reading its trivia) - Add regression test: standalone_method_leading_comment_attached Co-Authored-By: Claude Sonnet 4.6 --- .../source_analysis/parser/declarations.rs | 23 +++++++++++- .../src/source_analysis/parser/expressions.rs | 7 +++- .../src/source_analysis/parser/mod.rs | 37 ++++++++++++++++++- 3 files changed, 63 insertions(+), 4 deletions(-) diff --git a/crates/beamtalk-core/src/source_analysis/parser/declarations.rs b/crates/beamtalk-core/src/source_analysis/parser/declarations.rs index d10384cb6..507edce89 100644 --- a/crates/beamtalk-core/src/source_analysis/parser/declarations.rs +++ b/crates/beamtalk-core/src/source_analysis/parser/declarations.rs @@ -798,7 +798,12 @@ impl Parser { let pos_before = self.current; let mut comments = self.collect_comment_attachment(); let expr = self.parse_expression(); - comments.trailing = self.collect_trailing_comment(); + // Only collect trailing comment if parse_expression consumed tokens; + // otherwise collect_trailing_comment() reads the previous token's + // trivia, which belongs to the prior statement. + if self.current > pos_before { + comments.trailing = self.collect_trailing_comment(); + } let is_error = expr.is_error(); body.push(ExpressionStatement { comments, @@ -903,6 +908,11 @@ impl Parser { pub(super) fn parse_standalone_method_definition(&mut self) -> StandaloneMethodDefinition { let start = self.current_token().span(); + // Collect leading comments from the class-name token's leading trivia. + // parse_identifier() advances past the class name without reading trivia, + // so we must collect here before the token is consumed. + let mut class_leading_comments = self.collect_comment_attachment().leading; + // Parse class name let class_name = self.parse_identifier("Expected class name"); @@ -926,7 +936,7 @@ impl Parser { } // Parse method definition (selector => body) - let method = self.parse_method_definition().unwrap_or_else(|| { + let mut method = self.parse_method_definition().unwrap_or_else(|| { let span = self.current_token().span(); MethodDefinition::new( MessageSelector::Unary("error".into()), @@ -936,6 +946,15 @@ impl Parser { ) }); + // Prepend the class-name token's leading comments to the method's + // own comments. parse_method_definition() reads trivia from the + // selector token, so comments before the class name would otherwise + // be lost. + if !class_leading_comments.is_empty() { + class_leading_comments.append(&mut method.comments.leading); + method.comments.leading = class_leading_comments; + } + let span = start.merge(method.span); StandaloneMethodDefinition { diff --git a/crates/beamtalk-core/src/source_analysis/parser/expressions.rs b/crates/beamtalk-core/src/source_analysis/parser/expressions.rs index b414d6096..0b387b79a 100644 --- a/crates/beamtalk-core/src/source_analysis/parser/expressions.rs +++ b/crates/beamtalk-core/src/source_analysis/parser/expressions.rs @@ -643,7 +643,12 @@ impl Parser { let pos_before = self.current; let mut comments = self.collect_comment_attachment(); let expr = self.parse_expression(); - comments.trailing = self.collect_trailing_comment(); + // Only collect trailing comment if parse_expression consumed tokens; + // otherwise collect_trailing_comment() reads the previous token's + // trivia, which belongs to the prior statement. + if self.current > pos_before { + comments.trailing = self.collect_trailing_comment(); + } body.push(ExpressionStatement { comments, expression: expr, diff --git a/crates/beamtalk-core/src/source_analysis/parser/mod.rs b/crates/beamtalk-core/src/source_analysis/parser/mod.rs index 2b1b6320b..df618e6ea 100644 --- a/crates/beamtalk-core/src/source_analysis/parser/mod.rs +++ b/crates/beamtalk-core/src/source_analysis/parser/mod.rs @@ -755,9 +755,15 @@ impl Parser { let method_def = self.parse_standalone_method_definition(); method_definitions.push(method_def); } else { + let pos_before = self.current; let mut comments = self.collect_comment_attachment(); let expr = self.parse_expression(); - comments.trailing = self.collect_trailing_comment(); + // Only collect trailing comment if parse_expression consumed tokens; + // otherwise collect_trailing_comment() reads the previous token's + // trivia, which belongs to the prior statement. + if self.current > pos_before { + comments.trailing = self.collect_trailing_comment(); + } let is_error = expr.is_error(); expressions.push(ExpressionStatement { comments, @@ -4868,4 +4874,33 @@ Actor subclass: Counter block.body[0].comments.leading[0].content ); } + + #[test] + fn standalone_method_leading_comment_attached() { + // A `//` comment before a standalone method definition (`ClassName >> ...`) + // must appear as a leading comment on the MethodDefinition. + // Regression test: previously parse_standalone_method_definition() dropped + // comments from the class-name token's leading trivia. + let source = "// Note about Counter\nCounter >> increment => self.n := self.n + 1\n"; + let (module, diagnostics) = parse(lex_with_eof(source)); + assert!( + diagnostics.is_empty(), + "expected no diagnostics: {diagnostics:?}" + ); + assert_eq!(module.method_definitions.len(), 1); + let method = &module.method_definitions[0].method; + assert_eq!( + method.comments.leading.len(), + 1, + "expected one leading comment on standalone method" + ); + assert!( + method.comments.leading[0] + .content + .contains("Note about Counter"), + "content: {}", + method.comments.leading[0].content + ); + assert!(module.file_leading_comments.is_empty()); + } }