eclipse-jdt / eclipse-jdt/eclipse.jdt.core

[4.35+] Refactor ConditionalExpression and SwitchExpression by making them implement INumericChoiceContext

Open
#3,225 0 comments 0 reactions 1 assignee Claimed by @srikanth-sankaran View on GitHub
Modernization
Dominant language
Java
Stars
237
Forks
195
Avg merge
1d 12h
Merged PRs (30d)
47

Description

JLS 5.6 classifies `SwitchExpression` and `ConditionalExpression` as constructs in numeric choice context (when all result expressions are numeric) The computation of result type, their polyness or not all are all similarly defined. Essentially a switch is multi-way-conditional.

As such there is enormous room for code sharing by hoisting contract and default behavior to a new interface type say `INumericChoiceContext` that both switch expressions and ternary operators implement.

Comparing `org.eclipse.jdt.internal.compiler.ast.SwitchExpression.resolveType(BlockScope)` and `org.eclipse.jdt.internal.compiler.ast.ConditionalExpression.resolveType(BlockScope)` it is possible for the latter to be as minimal as the former.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.