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

Commit 090eac9

Browse files
author
Sarah Marshall
committed
Deprecate new array expression
1 parent 28dc3bc commit 090eac9

File tree

9 files changed

+395
-201
lines changed

9 files changed

+395
-201
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
@@ -956,6 +957,8 @@ type DiagnosticItem =
956957
| WarningCode.DeprecatedQubitBindingKeyword ->
957958
"The \"{0}\" keyword has been replaced with \"{1}\", and qubits may now be allocated without a block. "
958959
+ "Consider \"{1} q = Qubit();\" or \"{1} q = Qubit() {{ ... }}\"."
960+
| WarningCode.DeprecatedNewArray ->
961+
"Deprecated syntax. Use [] to construct an empty array, or [x, size = n] to construct an array of x repeated n times."
959962
| WarningCode.DeprecatedRUSloopInFunction ->
960963
"The use of repeat-until-success-loops within functions may not be supported in the future. Please use a while-loop instead."
961964

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
@@ -32,12 +32,12 @@ type GlobalVerificationTests() =
3232
this.Expect "LocalNamespaceShortNames1" []
3333
this.Expect "LocalNamespaceShortNames2" []
3434
this.Expect "LocalNamespaceShortNames3" [ Error ErrorCode.UnknownType ]
35-
this.Expect "LocalNamespaceShortNames4" [ Error ErrorCode.UnknownType ]
35+
this.Expect "LocalNamespaceShortNames4" [ Error ErrorCode.UnknownType; Warning WarningCode.DeprecatedNewArray ]
3636
this.Expect "LocalNamespaceShortNames5" [ Error ErrorCode.UnknownIdentifier ]
3737
this.Expect "LocalNamespaceShortNames6" [ Error ErrorCode.TypeMismatch; Error ErrorCode.TypeMismatch ]
3838
this.Expect "LocalNamespaceShortNames7" [ Error ErrorCode.UnknownIdentifier ]
3939
this.Expect "LocalNamespaceShortNames8" []
40-
this.Expect "LocalNamespaceShortNames9" []
40+
this.Expect "LocalNamespaceShortNames9" [ Warning WarningCode.DeprecatedNewArray ]
4141
this.Expect "LocalNamespaceShortNames10" []
4242
this.Expect "LocalNamespaceShortNames11" [ Error ErrorCode.UnknownType; Error ErrorCode.UnknownIdentifier ]
4343
this.Expect "LocalNamespaceShortNames12" [ Error ErrorCode.UnknownIdentifier ]
@@ -50,7 +50,7 @@ type GlobalVerificationTests() =
5050
this.Expect "LocalNamespaceShortNames19" []
5151
this.Expect "LocalNamespaceShortNames20" []
5252
this.Expect "LocalNamespaceShortNames21" []
53-
this.Expect "LocalNamespaceShortNames22" []
53+
this.Expect "LocalNamespaceShortNames22" (Warning WarningCode.DeprecatedNewArray |> List.replicate 2)
5454
this.Expect "LocalNamespaceShortNames23" []
5555
this.Expect "LocalNamespaceShortNames24" []
5656

@@ -530,7 +530,7 @@ type GlobalVerificationTests() =
530530
this.Expect "ValidAttributes1" []
531531
this.Expect "ValidAttributes2" []
532532
this.Expect "ValidAttributes3" []
533-
this.Expect "ValidAttributes4" []
533+
this.Expect "ValidAttributes4" [ Warning WarningCode.DeprecatedNewArray ]
534534
this.Expect "ValidAttributes5" []
535535
this.Expect "ValidAttributes6" []
536536
this.Expect "ValidAttributes7" []
@@ -552,7 +552,14 @@ type GlobalVerificationTests() =
552552
this.Expect "InvalidAttributes5" [ Error ErrorCode.UnknownTypeInNamespace ]
553553
this.Expect "InvalidAttributes6" [ Error ErrorCode.AttributeArgumentTypeMismatch ]
554554
this.Expect "InvalidAttributes7" [ Error ErrorCode.InvalidAttributeArgument ]
555-
this.Expect "InvalidAttributes8" [ Error ErrorCode.ArgumentOfUserDefinedTypeInAttribute ]
555+
556+
this.Expect
557+
"InvalidAttributes8"
558+
[
559+
Error ErrorCode.ArgumentOfUserDefinedTypeInAttribute
560+
Warning WarningCode.DeprecatedNewArray
561+
]
562+
556563
this.Expect "InvalidAttributes9" [ Error ErrorCode.MisplacedDeclarationAttribute ]
557564
this.Expect "InvalidAttributes10" [ Error ErrorCode.MisplacedDeclarationAttribute ]
558565
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
@@ -44,25 +44,25 @@ type LocalVerificationTests() =
4444

4545
this.Expect "TypeArgumentsInference6" []
4646
this.Expect "TypeArgumentsInference7" []
47-
this.Expect "TypeArgumentsInference8" []
48-
this.Expect "TypeArgumentsInference9" []
47+
this.Expect "TypeArgumentsInference8" [ Warning WarningCode.DeprecatedNewArray ]
48+
this.Expect "TypeArgumentsInference9" [ Warning WarningCode.DeprecatedNewArray ]
4949
this.Expect "TypeArgumentsInference10" []
5050
this.Expect "TypeArgumentsInference11" []
5151
this.Expect "TypeArgumentsInference12" []
5252
this.Expect "TypeArgumentsInference13" []
5353
this.Expect "TypeArgumentsInference14" []
5454
this.Expect "TypeArgumentsInference15" []
55-
this.Expect "TypeArgumentsInference16" []
56-
this.Expect "TypeArgumentsInference17" []
57-
this.Expect "TypeArgumentsInference18" []
55+
this.Expect "TypeArgumentsInference16" [ Warning WarningCode.DeprecatedNewArray ]
56+
this.Expect "TypeArgumentsInference17" [ Warning WarningCode.DeprecatedNewArray ]
57+
this.Expect "TypeArgumentsInference18" [ Warning WarningCode.DeprecatedNewArray ]
5858
this.Expect "TypeArgumentsInference19" []
5959
this.Expect "TypeArgumentsInference20" []
6060
this.Expect "TypeArgumentsInference21" [ Error ErrorCode.TypeMismatch ]
6161
this.Expect "TypeArgumentsInference22" [ Error ErrorCode.TypeMismatch ]
6262
this.Expect "TypeArgumentsInference23" []
6363
this.Expect "TypeArgumentsInference24" []
64-
this.Expect "TypeArgumentsInference25" []
65-
this.Expect "TypeArgumentsInference26" []
64+
this.Expect "TypeArgumentsInference25" [ Warning WarningCode.DeprecatedNewArray ]
65+
this.Expect "TypeArgumentsInference26" [ Warning WarningCode.DeprecatedNewArray ]
6666
this.Expect "TypeArgumentsInference27" [ Error ErrorCode.TypeMismatch ]
6767
this.Expect "TypeArgumentsInference28" [ Error ErrorCode.TypeMismatch ]
6868
this.Expect "TypeArgumentsInference29" [ Error ErrorCode.InvalidCyclicTypeParameterResolution ]
@@ -85,8 +85,8 @@ type LocalVerificationTests() =
8585
this.Expect "TypeArgumentsInference33" [ Error ErrorCode.TypeMismatch ]
8686
this.Expect "TypeArgumentsInference34" []
8787
this.Expect "TypeArgumentsInference35" []
88-
this.Expect "TypeArgumentsInference36" []
89-
this.Expect "TypeArgumentsInference37" []
88+
this.Expect "TypeArgumentsInference36" [ Warning WarningCode.DeprecatedNewArray ]
89+
this.Expect "TypeArgumentsInference37" [ Warning WarningCode.DeprecatedNewArray ]
9090
this.Expect "TypeArgumentsInference38" [ Error ErrorCode.TypeMismatch ]
9191
this.Expect "TypeArgumentsInference39" [ Error ErrorCode.TypeMismatch ]
9292
this.Expect "TypeArgumentsInference40" []
@@ -131,10 +131,10 @@ type LocalVerificationTests() =
131131

132132
this.Expect "VariableDeclaration15" []
133133
this.Expect "VariableDeclaration16" []
134-
this.Expect "VariableDeclaration17" []
135-
this.Expect "VariableDeclaration18" []
136-
this.Expect "VariableDeclaration19" []
137-
this.Expect "VariableDeclaration20" []
134+
this.Expect "VariableDeclaration17" [ Warning WarningCode.DeprecatedNewArray ]
135+
this.Expect "VariableDeclaration18" [ Warning WarningCode.DeprecatedNewArray ]
136+
this.Expect "VariableDeclaration19" [ Warning WarningCode.DeprecatedNewArray ]
137+
this.Expect "VariableDeclaration20" [ Warning WarningCode.DeprecatedNewArray ]
138138
this.Expect "VariableDeclaration21" []
139139
this.Expect "VariableDeclaration22" []
140140
this.Expect "VariableDeclaration23" []
@@ -154,7 +154,7 @@ type LocalVerificationTests() =
154154
this.Expect "CopyAndUpdateArray1" []
155155
this.Expect "CopyAndUpdateArray2" []
156156
this.Expect "CopyAndUpdateArray3" []
157-
this.Expect "CopyAndUpdateArray4" []
157+
this.Expect "CopyAndUpdateArray4" [ Warning WarningCode.DeprecatedNewArray ]
158158
this.Expect "CopyAndUpdateArray5" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ]
159159
this.Expect "CopyAndUpdateArray6" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ]
160160
this.Expect "CopyAndUpdateArray7" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ]
@@ -176,11 +176,23 @@ type LocalVerificationTests() =
176176
this.Expect "UpdateAndReassign3" []
177177
this.Expect "UpdateAndReassign4" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ]
178178
this.Expect "UpdateAndReassign5" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ]
179-
this.Expect "UpdateAndReassign6" []
180-
this.Expect "UpdateAndReassign7" []
181-
this.Expect "UpdateAndReassign8" []
182-
this.Expect "UpdateAndReassign9" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ]
183-
this.Expect "UpdateAndReassign10" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ]
179+
this.Expect "UpdateAndReassign6" [ Warning WarningCode.DeprecatedNewArray ]
180+
this.Expect "UpdateAndReassign7" [ Warning WarningCode.DeprecatedNewArray ]
181+
this.Expect "UpdateAndReassign8" [ Warning WarningCode.DeprecatedNewArray ]
182+
183+
this.Expect
184+
"UpdateAndReassign9"
185+
[
186+
Error ErrorCode.TypeMismatchInCopyAndUpdateExpr
187+
Warning WarningCode.DeprecatedNewArray
188+
]
189+
190+
this.Expect
191+
"UpdateAndReassign10"
192+
[
193+
Error ErrorCode.TypeMismatchInCopyAndUpdateExpr
194+
Warning WarningCode.DeprecatedNewArray
195+
]
184196

185197

186198
[<Fact>]
@@ -231,7 +243,7 @@ type LocalVerificationTests() =
231243
this.Expect "ItemAccess16" []
232244
this.Expect "ItemAccess17" []
233245
this.Expect "ItemAccess18" []
234-
this.Expect "ItemAccess19" []
246+
this.Expect "ItemAccess19" [ Warning WarningCode.DeprecatedNewArray ]
235247
this.Expect "ItemAccess20" []
236248

237249

@@ -252,22 +264,29 @@ type LocalVerificationTests() =
252264
Error ErrorCode.TypeMismatchInCopyAndUpdateExpr
253265
]
254266

255-
this.Expect "ItemUpdate9" []
267+
this.Expect "ItemUpdate9" [ Warning WarningCode.DeprecatedNewArray ]
256268

257269
this.Expect
258270
"ItemUpdate10"
259271
[
260272
Error ErrorCode.InvalidIdentifierExprInUpdate
261273
Error ErrorCode.ExcessContinuation
274+
Warning WarningCode.DeprecatedNewArray
262275
]
263276

264-
this.Expect "ItemUpdate11" [ Error ErrorCode.UpdateOfArrayItemExpr ]
277+
this.Expect
278+
"ItemUpdate11"
279+
[
280+
Error ErrorCode.UpdateOfArrayItemExpr
281+
Warning WarningCode.DeprecatedNewArray
282+
]
265283

266284
this.Expect
267285
"ItemUpdate12"
268286
[
269287
Error ErrorCode.TypeMismatchInCopyAndUpdateExpr
270288
Error ErrorCode.TypeMismatchInCopyAndUpdateExpr
289+
Warning WarningCode.DeprecatedNewArray
271290
]
272291

273292
this.Expect "ItemUpdate13" []
@@ -291,7 +310,7 @@ type LocalVerificationTests() =
291310
this.Expect "ItemUpdate18" [ Error ErrorCode.MissingFunctorForAutoGeneration ]
292311
this.Expect "ItemUpdate19" [ Error ErrorCode.MissingFunctorForAutoGeneration ]
293312
this.Expect "ItemUpdate20" []
294-
this.Expect "ItemUpdate21" []
313+
this.Expect "ItemUpdate21" [ Warning WarningCode.DeprecatedNewArray ]
295314
this.Expect "ItemUpdate22" []
296315

297316

@@ -371,7 +390,13 @@ type LocalVerificationTests() =
371390
this.Expect "UsingDepAttrInDepCall" [ Warning WarningCode.DeprecationWithoutRedirect ]
372391
this.Expect "UsingDepTypeInDepCall" [ Warning WarningCode.DeprecationWithoutRedirect ]
373392

374-
this.Expect "UsingDeprecatedType1" [ Warning WarningCode.DeprecationWithoutRedirect ]
393+
this.Expect
394+
"UsingDeprecatedType1"
395+
[
396+
Warning WarningCode.DeprecationWithoutRedirect
397+
Warning WarningCode.DeprecatedNewArray
398+
]
399+
375400
this.Expect "UsingDeprecatedType2" [ Warning WarningCode.DeprecationWithoutRedirect ]
376401
this.Expect "UsingDeprecatedType3" [ Warning WarningCode.DeprecationWithoutRedirect ]
377402

@@ -389,7 +414,13 @@ type LocalVerificationTests() =
389414
Warning WarningCode.DeprecationWithoutRedirect
390415
]
391416

392-
this.Expect "UsingRenamedType1" [ Warning WarningCode.DeprecationWithRedirect ]
417+
this.Expect
418+
"UsingRenamedType1"
419+
[
420+
Warning WarningCode.DeprecationWithRedirect
421+
Warning WarningCode.DeprecatedNewArray
422+
]
423+
393424
this.Expect "UsingRenamedType2" [ Warning WarningCode.DeprecationWithRedirect ]
394425
this.Expect "UsingRenamedType3" [ Warning WarningCode.DeprecationWithRedirect ]
395426

0 commit comments

Comments
 (0)