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

Commit f31cfaf

Browse files
authored
Deprecate new array expression (#956)
1 parent 9dcd272 commit f31cfaf

File tree

11 files changed

+405
-210
lines changed

11 files changed

+405
-210
lines changed

src/QsCompiler/DataStructures/Diagnostics.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ type WarningCode =
369369
| [<Obsolete("This diagnostic is no longer in use. The error InvalidUseOfUnderscorePattern is given instead.")>] UseOfUnderscorePattern = 3305
370370
| DeprecatedTupleBrackets = 3306
371371
| DeprecatedQubitBindingKeyword = 3307
372+
| DeprecatedNewArray = 3308
372373
| DeprecatedRUSloopInFunction = 4001
373374

374375
| DiscardingItemInAssignment = 5001
@@ -954,6 +955,8 @@ type DiagnosticItem =
954955
| WarningCode.DeprecatedQubitBindingKeyword ->
955956
"The \"{0}\" keyword has been replaced with \"{1}\", and qubits may now be allocated without a block. "
956957
+ "Consider \"{1} q = Qubit();\" or \"{1} q = Qubit() {{ ... }}\"."
958+
| WarningCode.DeprecatedNewArray ->
959+
"Deprecated syntax. Use [] to construct an empty array, or [x, size = n] to construct an array of x repeated n times."
957960
| WarningCode.DeprecatedRUSloopInFunction ->
958961
"The use of repeat-until-success-loops within functions may not be supported in the future. Please use a while-loop instead."
959962

src/QsCompiler/Tests.Compiler/AccessModifierTests.fs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ type AccessModifierTests() =
2727

2828
[<Fact>]
2929
member this.Types() =
30-
this.Expect "TypeUseOK" []
31-
this.Expect "TypeReferenceInternalInaccessible" [ Error ErrorCode.InaccessibleType ]
30+
this.Expect "TypeUseOK" (Warning WarningCode.DeprecatedNewArray |> List.replicate 3)
31+
32+
this.Expect
33+
"TypeReferenceInternalInaccessible"
34+
[ Error ErrorCode.InaccessibleType; Warning WarningCode.DeprecatedNewArray ]
35+
3236
this.Expect "TypeConstructorReferenceInternalInaccessible" [ Error ErrorCode.InaccessibleCallable ]
3337

3438
[<Fact>]

src/QsCompiler/Tests.Compiler/GlobalVerificationTests.fs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ type GlobalVerificationTests() =
3535
this.Expect "LocalNamespaceShortNames1" []
3636
this.Expect "LocalNamespaceShortNames2" []
3737
this.Expect "LocalNamespaceShortNames3" [ Error ErrorCode.UnknownType ]
38-
this.Expect "LocalNamespaceShortNames4" [ Error ErrorCode.UnknownType ]
38+
this.Expect "LocalNamespaceShortNames4" [ Error ErrorCode.UnknownType; Warning WarningCode.DeprecatedNewArray ]
3939
this.Expect "LocalNamespaceShortNames5" [ Error ErrorCode.UnknownIdentifier ]
4040
this.Expect "LocalNamespaceShortNames6" [ Error ErrorCode.TypeMismatch; Error ErrorCode.TypeMismatch ]
4141
this.Expect "LocalNamespaceShortNames7" [ Error ErrorCode.UnknownIdentifier ]
4242
this.Expect "LocalNamespaceShortNames8" []
43-
this.Expect "LocalNamespaceShortNames9" []
43+
this.Expect "LocalNamespaceShortNames9" [ Warning WarningCode.DeprecatedNewArray ]
4444
this.Expect "LocalNamespaceShortNames10" []
4545
this.Expect "LocalNamespaceShortNames11" [ Error ErrorCode.UnknownType; Error ErrorCode.UnknownIdentifier ]
4646
this.Expect "LocalNamespaceShortNames12" [ Error ErrorCode.UnknownIdentifier ]
@@ -53,7 +53,7 @@ type GlobalVerificationTests() =
5353
this.Expect "LocalNamespaceShortNames19" []
5454
this.Expect "LocalNamespaceShortNames20" []
5555
this.Expect "LocalNamespaceShortNames21" []
56-
this.Expect "LocalNamespaceShortNames22" []
56+
this.Expect "LocalNamespaceShortNames22" (Warning WarningCode.DeprecatedNewArray |> List.replicate 2)
5757
this.Expect "LocalNamespaceShortNames23" []
5858
this.Expect "LocalNamespaceShortNames24" []
5959

@@ -533,7 +533,7 @@ type GlobalVerificationTests() =
533533
this.Expect "ValidAttributes1" []
534534
this.Expect "ValidAttributes2" []
535535
this.Expect "ValidAttributes3" []
536-
this.Expect "ValidAttributes4" []
536+
this.Expect "ValidAttributes4" [ Warning WarningCode.DeprecatedNewArray ]
537537
this.Expect "ValidAttributes5" []
538538
this.Expect "ValidAttributes6" []
539539
this.Expect "ValidAttributes7" []
@@ -555,7 +555,14 @@ type GlobalVerificationTests() =
555555
this.Expect "InvalidAttributes5" [ Error ErrorCode.UnknownTypeInNamespace ]
556556
this.Expect "InvalidAttributes6" [ Error ErrorCode.AttributeArgumentTypeMismatch ]
557557
this.Expect "InvalidAttributes7" [ Error ErrorCode.InvalidAttributeArgument ]
558-
this.Expect "InvalidAttributes8" [ Error ErrorCode.ArgumentOfUserDefinedTypeInAttribute ]
558+
559+
this.Expect
560+
"InvalidAttributes8"
561+
[
562+
Error ErrorCode.ArgumentOfUserDefinedTypeInAttribute
563+
Warning WarningCode.DeprecatedNewArray
564+
]
565+
559566
this.Expect "InvalidAttributes9" [ Error ErrorCode.MisplacedDeclarationAttribute ]
560567
this.Expect "InvalidAttributes10" [ Error ErrorCode.MisplacedDeclarationAttribute ]
561568
this.Expect "InvalidAttributes11" [ Error ErrorCode.MisplacedDeclarationAttribute ]

src/QsCompiler/Tests.Compiler/LocalVerificationTests.fs

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,25 @@ type LocalVerificationTests() =
4747

4848
this.Expect "TypeArgumentsInference6" []
4949
this.Expect "TypeArgumentsInference7" []
50-
this.Expect "TypeArgumentsInference8" []
51-
this.Expect "TypeArgumentsInference9" []
50+
this.Expect "TypeArgumentsInference8" [ Warning WarningCode.DeprecatedNewArray ]
51+
this.Expect "TypeArgumentsInference9" [ Warning WarningCode.DeprecatedNewArray ]
5252
this.Expect "TypeArgumentsInference10" []
5353
this.Expect "TypeArgumentsInference11" []
5454
this.Expect "TypeArgumentsInference12" []
5555
this.Expect "TypeArgumentsInference13" []
5656
this.Expect "TypeArgumentsInference14" []
5757
this.Expect "TypeArgumentsInference15" []
58-
this.Expect "TypeArgumentsInference16" []
59-
this.Expect "TypeArgumentsInference17" []
60-
this.Expect "TypeArgumentsInference18" []
58+
this.Expect "TypeArgumentsInference16" [ Warning WarningCode.DeprecatedNewArray ]
59+
this.Expect "TypeArgumentsInference17" [ Warning WarningCode.DeprecatedNewArray ]
60+
this.Expect "TypeArgumentsInference18" [ Warning WarningCode.DeprecatedNewArray ]
6161
this.Expect "TypeArgumentsInference19" []
6262
this.Expect "TypeArgumentsInference20" []
6363
this.Expect "TypeArgumentsInference21" [ Error ErrorCode.TypeMismatch ]
6464
this.Expect "TypeArgumentsInference22" [ Error ErrorCode.TypeMismatch ]
6565
this.Expect "TypeArgumentsInference23" []
6666
this.Expect "TypeArgumentsInference24" []
67-
this.Expect "TypeArgumentsInference25" []
68-
this.Expect "TypeArgumentsInference26" []
67+
this.Expect "TypeArgumentsInference25" [ Warning WarningCode.DeprecatedNewArray ]
68+
this.Expect "TypeArgumentsInference26" [ Warning WarningCode.DeprecatedNewArray ]
6969
this.Expect "TypeArgumentsInference27" [ Error ErrorCode.TypeMismatch ]
7070
this.Expect "TypeArgumentsInference28" [ Error ErrorCode.TypeMismatch ]
7171
this.Expect "TypeArgumentsInference29" [ Error ErrorCode.InvalidCyclicTypeParameterResolution ]
@@ -88,8 +88,8 @@ type LocalVerificationTests() =
8888
this.Expect "TypeArgumentsInference33" [ Error ErrorCode.TypeMismatch ]
8989
this.Expect "TypeArgumentsInference34" []
9090
this.Expect "TypeArgumentsInference35" []
91-
this.Expect "TypeArgumentsInference36" []
92-
this.Expect "TypeArgumentsInference37" []
91+
this.Expect "TypeArgumentsInference36" [ Warning WarningCode.DeprecatedNewArray ]
92+
this.Expect "TypeArgumentsInference37" [ Warning WarningCode.DeprecatedNewArray ]
9393
this.Expect "TypeArgumentsInference38" [ Error ErrorCode.TypeMismatch ]
9494
this.Expect "TypeArgumentsInference39" [ Error ErrorCode.TypeMismatch ]
9595
this.Expect "TypeArgumentsInference40" []
@@ -134,10 +134,10 @@ type LocalVerificationTests() =
134134

135135
this.Expect "VariableDeclaration15" []
136136
this.Expect "VariableDeclaration16" []
137-
this.Expect "VariableDeclaration17" []
138-
this.Expect "VariableDeclaration18" []
139-
this.Expect "VariableDeclaration19" []
140-
this.Expect "VariableDeclaration20" []
137+
this.Expect "VariableDeclaration17" [ Warning WarningCode.DeprecatedNewArray ]
138+
this.Expect "VariableDeclaration18" [ Warning WarningCode.DeprecatedNewArray ]
139+
this.Expect "VariableDeclaration19" [ Warning WarningCode.DeprecatedNewArray ]
140+
this.Expect "VariableDeclaration20" [ Warning WarningCode.DeprecatedNewArray ]
141141
this.Expect "VariableDeclaration21" []
142142
this.Expect "VariableDeclaration22" []
143143
this.Expect "VariableDeclaration23" []
@@ -157,7 +157,7 @@ type LocalVerificationTests() =
157157
this.Expect "CopyAndUpdateArray1" []
158158
this.Expect "CopyAndUpdateArray2" []
159159
this.Expect "CopyAndUpdateArray3" []
160-
this.Expect "CopyAndUpdateArray4" []
160+
this.Expect "CopyAndUpdateArray4" [ Warning WarningCode.DeprecatedNewArray ]
161161
this.Expect "CopyAndUpdateArray5" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ]
162162
this.Expect "CopyAndUpdateArray6" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ]
163163
this.Expect "CopyAndUpdateArray7" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ]
@@ -179,11 +179,23 @@ type LocalVerificationTests() =
179179
this.Expect "UpdateAndReassign3" []
180180
this.Expect "UpdateAndReassign4" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ]
181181
this.Expect "UpdateAndReassign5" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ]
182-
this.Expect "UpdateAndReassign6" []
183-
this.Expect "UpdateAndReassign7" []
184-
this.Expect "UpdateAndReassign8" []
185-
this.Expect "UpdateAndReassign9" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ]
186-
this.Expect "UpdateAndReassign10" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ]
182+
this.Expect "UpdateAndReassign6" [ Warning WarningCode.DeprecatedNewArray ]
183+
this.Expect "UpdateAndReassign7" [ Warning WarningCode.DeprecatedNewArray ]
184+
this.Expect "UpdateAndReassign8" [ Warning WarningCode.DeprecatedNewArray ]
185+
186+
this.Expect
187+
"UpdateAndReassign9"
188+
[
189+
Error ErrorCode.TypeMismatchInCopyAndUpdateExpr
190+
Warning WarningCode.DeprecatedNewArray
191+
]
192+
193+
this.Expect
194+
"UpdateAndReassign10"
195+
[
196+
Error ErrorCode.TypeMismatchInCopyAndUpdateExpr
197+
Warning WarningCode.DeprecatedNewArray
198+
]
187199

188200

189201
[<Fact>]
@@ -234,7 +246,7 @@ type LocalVerificationTests() =
234246
this.Expect "ItemAccess16" []
235247
this.Expect "ItemAccess17" []
236248
this.Expect "ItemAccess18" []
237-
this.Expect "ItemAccess19" []
249+
this.Expect "ItemAccess19" [ Warning WarningCode.DeprecatedNewArray ]
238250
this.Expect "ItemAccess20" []
239251

240252

@@ -255,22 +267,29 @@ type LocalVerificationTests() =
255267
Error ErrorCode.TypeMismatchInCopyAndUpdateExpr
256268
]
257269

258-
this.Expect "ItemUpdate9" []
270+
this.Expect "ItemUpdate9" [ Warning WarningCode.DeprecatedNewArray ]
259271

260272
this.Expect
261273
"ItemUpdate10"
262274
[
263275
Error ErrorCode.InvalidIdentifierExprInUpdate
264276
Error ErrorCode.ExcessContinuation
277+
Warning WarningCode.DeprecatedNewArray
265278
]
266279

267-
this.Expect "ItemUpdate11" [ Error ErrorCode.UpdateOfArrayItemExpr ]
280+
this.Expect
281+
"ItemUpdate11"
282+
[
283+
Error ErrorCode.UpdateOfArrayItemExpr
284+
Warning WarningCode.DeprecatedNewArray
285+
]
268286

269287
this.Expect
270288
"ItemUpdate12"
271289
[
272290
Error ErrorCode.TypeMismatchInCopyAndUpdateExpr
273291
Error ErrorCode.TypeMismatchInCopyAndUpdateExpr
292+
Warning WarningCode.DeprecatedNewArray
274293
]
275294

276295
this.Expect "ItemUpdate13" []
@@ -294,7 +313,7 @@ type LocalVerificationTests() =
294313
this.Expect "ItemUpdate18" [ Error ErrorCode.MissingFunctorForAutoGeneration ]
295314
this.Expect "ItemUpdate19" [ Error ErrorCode.MissingFunctorForAutoGeneration ]
296315
this.Expect "ItemUpdate20" []
297-
this.Expect "ItemUpdate21" []
316+
this.Expect "ItemUpdate21" [ Warning WarningCode.DeprecatedNewArray ]
298317
this.Expect "ItemUpdate22" []
299318

300319

@@ -374,7 +393,13 @@ type LocalVerificationTests() =
374393
this.Expect "UsingDepAttrInDepCall" [ Warning WarningCode.DeprecationWithoutRedirect ]
375394
this.Expect "UsingDepTypeInDepCall" [ Warning WarningCode.DeprecationWithoutRedirect ]
376395

377-
this.Expect "UsingDeprecatedType1" [ Warning WarningCode.DeprecationWithoutRedirect ]
396+
this.Expect
397+
"UsingDeprecatedType1"
398+
[
399+
Warning WarningCode.DeprecationWithoutRedirect
400+
Warning WarningCode.DeprecatedNewArray
401+
]
402+
378403
this.Expect "UsingDeprecatedType2" [ Warning WarningCode.DeprecationWithoutRedirect ]
379404
this.Expect "UsingDeprecatedType3" [ Warning WarningCode.DeprecationWithoutRedirect ]
380405

@@ -392,7 +417,13 @@ type LocalVerificationTests() =
392417
Warning WarningCode.DeprecationWithoutRedirect
393418
]
394419

395-
this.Expect "UsingRenamedType1" [ Warning WarningCode.DeprecationWithRedirect ]
420+
this.Expect
421+
"UsingRenamedType1"
422+
[
423+
Warning WarningCode.DeprecationWithRedirect
424+
Warning WarningCode.DeprecatedNewArray
425+
]
426+
396427
this.Expect "UsingRenamedType2" [ Warning WarningCode.DeprecationWithRedirect ]
397428
this.Expect "UsingRenamedType3" [ Warning WarningCode.DeprecationWithRedirect ]
398429

0 commit comments

Comments
 (0)