Skip to content

Conversation

@JaroslavTulach
Copy link
Member

@JaroslavTulach JaroslavTulach commented Dec 18, 2025

Pull Request Description

  • Allow multi line if then else like
if a==b then
    action
else
    anotheraction

Important Notes

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • All code follows the
    Java,
    Rust
  • Unit tests have been written where possible.

@JaroslavTulach JaroslavTulach self-assigned this Dec 18, 2025
@JaroslavTulach JaroslavTulach changed the title Wip/jtulach/multi line if then else6408 Allow multiline if then else Dec 18, 2025
Copy link
Member

@jdunkerley jdunkerley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do a patch release we may need to include this as I expect libs will use it pretty quickly :)

Thank you and @kazcw for enabling this

let new_line =
block::Line { newline: line.newline.into(), expression: None };
block_lines[i - 1] = new_prev_line;
block_lines[i] = new_line;
Copy link
Member Author

@JaroslavTulach JaroslavTulach Dec 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • the 48731d4 commit tries to implement the same idea as has previously been done in TreeToIr
  • if 48731d4 gets polished, then 571f21a will not be needed
  • right now the Tree::multi_segment_app(all_segments) manual manipulation results in assertion error:
thread 'if_block_else_block' panicked at lib/rust/parser/src/source/span.rs:204:13:
assertion `left == right` failed
  left: Location { utf8: 18, utf16: 18, line: 1, col16: 5 }
 right: Location { utf8: 19, utf16: 19, line: 2, col16: 0 }
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/1159e78c4747b02ef996e55082b704c09b970588/library/std/src/panicking.rs:697:5
   1: core::panicking::panic_fmt
             at /rustc/1159e78c4747b02ef996e55082b704c09b970588/library/core/src/panicking.rs:75:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /.rustup/toolchains/1.90.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/panicking.rs:403:5
   4: enso_parser::source::span::Span::concat
             at enso/lib/rust/parser/src/source/span.rs:204:13
   5: <enso_parser::syntax::token::Token<T> as enso_parser::source::span::Builder>::add_to_span
             at enso/lib/rust/parser/src/source/span.rs:339:18
   6: enso_parser::source::span::Span::add
             at enso/lib/rust/parser/src/source/span.rs:179:9
   7: <enso_parser::syntax::tree::MultiSegmentAppSegment as enso_parser::source::span::Builder>::add_to_span
             at enso/lib/rust/parser/src/syntax/tree.rs:822:14
   8: <enso_prelude::data::non_empty_vec::NonEmptyVec<T> as enso_parser::source::span::Builder>::add_to_span::{{closure}}
             at enso/lib/rust/parser/src/source/span.rs:377:53
   9: <core::slice::iter::IterMut<T> as core::iter::traits::iterator::Iterator>::fold
             at /.rustup/toolchains/1.90.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/slice/iter/macros.rs:255:27
  10: <enso_prelude::data::non_empty_vec::NonEmptyVec<T> as enso_parser::source::span::Builder>::add_to_span
             at enso/lib/rust/parser/src/source/span.rs:377:26
  11: enso_parser::source::span::Span::add
             at enso/lib/rust/parser/src/source/span.rs:179:9
  12: enso_parser::syntax::tree::Tree::multi_segment_app
             at enso/lib/rust/parser/src/source/span.rs:300:63
  13: enso_parser::syntax::statement::compound_lines_maybe_with_tail
             at enso/lib/rust/parser/src/syntax/statement.rs:149:47
  14: enso_parser::syntax::statement::compound_lines_with_tail
             at enso/lib/rust/parser/src/syntax/statement.rs:88:5
  15: enso_parser::syntax::statement::BodyBlockParser::parse_body_block
             at enso/lib/rust/parser/src/syntax/statement.rs:47:26
  16: enso_parser::syntax::tree::block::parse_block
             at enso/lib/rust/parser/src/syntax/tree/block.rs:60:32
  17: <enso_parser::macros::resolver::ResolverState as enso_parser::syntax::expression::consumer::Finish>::finish
             at enso/lib/rust/parser/src/macros/resolver.rs:178:17
  18: <enso_parser::macros::resolver::Resolver as enso_parser::syntax::expression::consumer::Finish>::finish
             at enso/lib/rust/parser/src/macros/resolver.rs:252:23
  19: <enso_parser::lexer::Lexer<Inner> as enso_parser::syntax::expression::consumer::Finish>::finish
             at enso/lib/rust/parser/src/lexer.rs:1403:32
  20: enso_parser::Parser::run
             at enso/lib/rust/parser/src/lib.rs:178:80
  21: enso_parser::Parser::parse_block
             at enso/lib/rust/parser/src/lib.rs:173:14
  22: enso_parser_debug::test::parse_block
             at ./src/test.rs:61:42
  23: parse::if_block_else_block
             at ./tests/parse.rs:33:45
  24: parse::if_block_else_block::{{closure}}
             at ./tests/parse.rs:114:25
  25: core::ops::function::FnOnce::call_once
             at /.rustup/toolchains/1.90.0-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:253:5
  26: core::ops::function::FnOnce::call_once
             at /rustc/1159e78c4747b02ef996e55082b704c09b970588/library/core/src/ops/function.rs:253:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
test if_block_else_block ... FAILED
  • probably some locations aren't quite right yet
  • concatenating Trees from multiple lines without including the newline isn't being liked...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support multi-line if-then-else

4 participants