swiftlang / swift-syntax

A set of Swift libraries for parsing, inspecting, generating, and transforming Swift source code.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong insertion location in fix-it for missing parentheses around parameter type list

AnthonyLatsis opened this issue · comments

Description

It seems we’re forgetting about trailing trivia when computing the insertion location for the closing paren.

Steps to Reproduce

let _ : Float -> Int
error: expected '(' to start function type [bridged_error]
let _ : Float -> Int
        ^
note: insert '(' [bridged_note]
let _ : Float -> Int
        ^
        (
error: expected ')' in function type [bridged_error]
let _ : Float -> Int
              ^
note: insert ')' [bridged_note]
let _ : Float -> Int
             ~^
              )

Tracked in Apple’s issue tracker as rdar://121323841

@AnthonyLatsis

In TypeExprTests.swift, under testTypeExpr28(), it seems like this happens since this would be valid for a function type.

Insertions look right to me, as the resulting expression would be valid:

let _ : (Float) -> Int

What am I missing here?

The location of the insert ')' note, which points at the - character both in testTypeExpr28() and the terminal, does not match the insertion location of the fix-it, which in this particular case is immediately after the t in Float.

What is the expected behaviour when there are multiple whitespaces after Float
Current main branch code only keeps single whitespace after ), is this a bug as well?
eg.

let _: Float      -> Int // original
let _: (Float) -> Int // after fix-its

Honestly, I think any behavior is fine here. If it is easier to trim whitespace, that seems good but keeping them also sounds good to me.