-
Notifications
You must be signed in to change notification settings - Fork 334
Allow multiline if then else
#14522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Allow multiline if then else
#14522
Conversation
if then else
jdunkerley
left a comment
There was a problem hiding this 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; |
There was a problem hiding this comment.
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...
| let mut if_then_segments = prev_app.segments.clone(); | ||
| let else_segment = app.segments[0].clone(); | ||
| if_then_segments.push(else_segment); | ||
| let combined_multi_segment_app = Tree::multi_segment_app(if_then_segments); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Do you have any advice, @kazcw?
- This line panics with stack trace listed here
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 }```
- As far as I understand, the
else_segmentMultiSegmentAppSegmentdoes not follow the previousif_then_segments
- What should be the fix?
- Insert
NewLinebetween the segments somehow? - Expand the span of last
if_then_segmentssegment? - Change the start of
else_segmentto directly follow the lastif_then_segmentssegment?
- Insert
- Thanks in advance for any advice.
Pull Request Description
if then elselikeif-then-else#6408Important Notes
IfThenElseIR instead ofif_then_elsefunction invocation #11365 supportIfThenElsewithout else branchelseapplicationChecklist
Please ensure that the following checklist has been satisfied before submitting the PR:
Java,
Rust