diff --git a/gdtoolkit/formatter/expression.py b/gdtoolkit/formatter/expression.py index 3540fb2d..31457680 100644 --- a/gdtoolkit/formatter/expression.py +++ b/gdtoolkit/formatter/expression.py @@ -746,10 +746,18 @@ def _format_dot_chain_to_multiple_lines_bottom_up( context: Context, ) -> FormattedLines: last_chain_element = dot_chain.children[-1] - if isinstance(last_chain_element, Token) or last_chain_element.data not in [ - "actual_getattr_call", - "actual_subscr_expr", - ]: + if ( + isinstance(last_chain_element, Token) + or last_chain_element.data + not in [ + "actual_getattr_call", + "actual_subscr_expr", + ] + or ( + last_chain_element.data == "actual_getattr_call" + and any(expression_contains_lambda(e) for e in dot_chain.children[:-1]) + ) + ): return _format_operator_chain_based_expression_to_multiple_lines( dot_chain, expression_context, context ) diff --git a/tests/formatter/input-output-pairs/bug_334_multiline_lambda.in.gd b/tests/formatter/input-output-pairs/bug_334_multiline_lambda.in.gd new file mode 100644 index 00000000..73fa7389 --- /dev/null +++ b/tests/formatter/input-output-pairs/bug_334_multiline_lambda.in.gd @@ -0,0 +1,12 @@ +class WeaponSystemBullet extends Node: + pass +func foo(): + var bullet_scene + assert( + (func() -> bool: + var test_instance: Node = bullet_scene.instantiate() + var is_needed_class: bool = test_instance is WeaponSystemBullet + test_instance.free() + return is_needed_class) + .call() + ) diff --git a/tests/formatter/input-output-pairs/bug_334_multiline_lambda.out.gd b/tests/formatter/input-output-pairs/bug_334_multiline_lambda.out.gd new file mode 100644 index 00000000..bc82ce6f --- /dev/null +++ b/tests/formatter/input-output-pairs/bug_334_multiline_lambda.out.gd @@ -0,0 +1,17 @@ +class WeaponSystemBullet: + extends Node + pass + + +func foo(): + var bullet_scene + assert( + ( + (func() -> bool: + var test_instance: Node = bullet_scene.instantiate() + var is_needed_class: bool = test_instance is WeaponSystemBullet + test_instance.free() + return is_needed_class) + . call() + ) + )