eclipse-xtext / eclipse-xtext/xtext

Misleading formatted indentation in nested if-statements when using ? :

Open
#2,337 27 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug confirmed good first issue
Dominant language
Java
Stars
831
Forks
330
Avg merge
3d 7h
Merged PRs (30d)
12

Description

Consider the following Xtend class after formatting: (branches are labelled based on ? and :. Code has been formatted)

@Data class Foo {
	val Collection<Object> open
	val Collection<Object> closed
	val Object[][] area
	private def checkNode(Object curr, int x, int y) {
		area.get(x, y) => [
			closed.contains(it)
				? !open.contains(it) // If-1
				? { // If-2
				setData(curr)
				open.add(it)
			} : checkBetter(curr) // Else-A
				? { // If-3
				open.add(it)
			}
		]
	}
	def setData(Object a, Object b) {/*Irrelevant*/}
	def checkBetter(Object a, Object b) {/*Irrelevant*/}
}

The branch labelled Else-A belongs to If-2, although based on the indentation it seems as if it belonged to If-1.
The content of the whole If-2-Else-A block (including the block If-3) is missing a level of indentation.
In case it matters, the line width is 110 and indentation uses tabs.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided formatted Xtend example and trace the formatter behavior for nested if-statements using the ? and : branches. Verify that Else-A belongs to If-2 and that the If-2–Else-A block is indented consistently; done means the formatted output makes both relationships clear.

Written by the indexing model from the issue text.

Assessment

Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.