Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 60b843b

Browse files
author
Sarah Marshall
committed
Fix NewArray expression range
1 parent 090eac9 commit 60b843b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/QsCompiler/TextProcessor/QsExpressionParsing.fs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,24 +470,28 @@ let private valueArray =
470470
<|> bracketDefinedCommaSepExpr (lArray, rArray)
471471

472472
/// Parses a Q# array declaration as QsExpression.
473-
/// Raises an InvalidContructorExpression if the array declaration keyword is not followed by a valid array constructor,
473+
/// Adds an InvalidConstructorExpression if the array declaration keyword is not followed by a valid array constructor,
474474
/// and advances to the next whitespace character or QsFragmentHeader.
475475
let private newArray =
476476
let itemType = expectedQsType (lArray >>% ()) >>= fun itemType -> validateTypeSyntax true itemType >>% itemType
477477
let body = itemType .>>. (arrayBrackets (expectedExpr eof) |>> fst) |>> NewArray
478478

479+
let toExpr headRange (kind, bodyRange) =
480+
QsExpression.New(kind, Range.Span headRange bodyRange)
481+
479482
let invalid =
480483
checkForInvalid
481484
(qsFragmentHeader >>% "" <|> (nextCharSatisfies Text.IsWhitespace >>. emptySpace))
482485
ErrorCode.InvalidConstructorExpression
483486
>>% unknownExpr
484487

485488
let withWarning (expr: QsExpression) =
486-
// TODO: Diagnostic range doesn't cover the entire expression.
487489
let range = expr.Range |> QsNullable.defaultValue Range.Zero
488490
QsCompilerDiagnostic.Warning (WarningCode.DeprecatedNewArray, []) range |> pushDiagnostic >>% expr
489491

490-
arrayDecl.parse >>. (term body |>> QsExpression.New <|> (term invalid |>> fst)) >>= withWarning
492+
arrayDecl.parse
493+
>>= fun headRange -> term body |>> toExpr headRange <|> (term invalid |>> fst)
494+
>>= withWarning
491495

492496
/// used to temporarily store item accessors for both array item and named item access expressions
493497
type private ItemAccessor =

0 commit comments

Comments
 (0)