ballerina-platform / ballerina-spec

Ballerina Language and Platform Specifications
Other
167 stars 53 forks source link

Clarification on unreachable panic statement #1292

Open mindula opened 8 months ago

mindula commented 8 months ago

Description:

Consider the below scenario, where there's an unreachable panic error("") statement followed by a variable assignment. Shouldn't we suggest the unreachable code error for the panic statement? Currently, if there's another statement, such as a variable assignment, after the panic statement, we are suggesting the unreachable code error for the variable assignment.

Screenshot 2024-03-07 at 11 12 11

The spec says,

It is a compile error if a statement other than a panic-stmt is not reachable.

Is there a reason for not suggesting the unreachable code error for panic statements?

Suggested Labels:

Code sample that shows issue:

function test() returns error? {
    from var item in 1 ... 5
    where true
    do {
        if true {
            return;
        }
        panic error("Panic!");
        int _ = 2;
    };
}

Related Issues: https://github.com/ballerina-platform/ballerina-lang/issues/42105