Skip to content

Improve CE Combine/Delay error reporting ranges #18422

@edgarfgp

Description

@edgarfgp

Is your feature request related to a problem? Please describe.

Currently when implementing Combine and Delay CE members the error reporting uses the the complete ranges of all the expressions involved. e.g.

Describe the solution you'd like

Instead of using the complete range, we should be using the ranges of the expressions after the first one as this are the expressions that we are trying to Combine

type ListBuilder() =

    member this.Yield(x) = [x]

    member this.For(m,f) =
        m |> List.collect f

    member this.Combine (a,b) =
        List.concat [a;b]

    // member this.Delay(f) = f()
    
let listBuilder = new ListBuilder()

let result = listBuilder {
    let a = 10
    yield a
    if true then
    ^^^^^^^^^^^^
        yield 20
        ^^^^^^^^
    else
    ^^^^
        yield 30
        ^^^^^^^^
}	

Alternatively we can only uses the range for the places where we are actually using return or yield. For this we will need to use error recovery errorR but that might show errors hidden on purpose due to unhandled cases in the following phases.

type ListBuilder() =

    member this.Yield(x) = [x]

    member this.For(m,f) =
        m |> List.collect f

    member this.Combine (a,b) =
        List.concat [a;b]

    // member this.Delay(f) = f()
    
let listBuilder = new ListBuilder()

let result = listBuilder {
    let a = 10
    yield a
    if true then
        yield 20
        ^^^^^
    else
        yield 30
        ^^^^^
}

Describe alternatives you've considered

A clear and concise description of any alternative solutions or features you've considered.

Additional context

If the issue is about:

Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions