diff --git a/src/QsCompiler/DataStructures/Diagnostics.fs b/src/QsCompiler/DataStructures/Diagnostics.fs index 50e77301e3..e4476b0977 100644 --- a/src/QsCompiler/DataStructures/Diagnostics.fs +++ b/src/QsCompiler/DataStructures/Diagnostics.fs @@ -369,6 +369,7 @@ type WarningCode = | [] UseOfUnderscorePattern = 3305 | DeprecatedTupleBrackets = 3306 | DeprecatedQubitBindingKeyword = 3307 + | DeprecatedNewArray = 3308 | DeprecatedRUSloopInFunction = 4001 | DiscardingItemInAssignment = 5001 @@ -954,6 +955,8 @@ type DiagnosticItem = | WarningCode.DeprecatedQubitBindingKeyword -> "The \"{0}\" keyword has been replaced with \"{1}\", and qubits may now be allocated without a block. " + "Consider \"{1} q = Qubit();\" or \"{1} q = Qubit() {{ ... }}\"." + | WarningCode.DeprecatedNewArray -> + "Deprecated syntax. Use [] to construct an empty array, or [x, size = n] to construct an array of x repeated n times." | WarningCode.DeprecatedRUSloopInFunction -> "The use of repeat-until-success-loops within functions may not be supported in the future. Please use a while-loop instead." diff --git a/src/QsCompiler/Tests.Compiler/AccessModifierTests.fs b/src/QsCompiler/Tests.Compiler/AccessModifierTests.fs index 60d67d1cbf..bfa56e5677 100644 --- a/src/QsCompiler/Tests.Compiler/AccessModifierTests.fs +++ b/src/QsCompiler/Tests.Compiler/AccessModifierTests.fs @@ -27,8 +27,12 @@ type AccessModifierTests() = [] member this.Types() = - this.Expect "TypeUseOK" [] - this.Expect "TypeReferenceInternalInaccessible" [ Error ErrorCode.InaccessibleType ] + this.Expect "TypeUseOK" (Warning WarningCode.DeprecatedNewArray |> List.replicate 3) + + this.Expect + "TypeReferenceInternalInaccessible" + [ Error ErrorCode.InaccessibleType; Warning WarningCode.DeprecatedNewArray ] + this.Expect "TypeConstructorReferenceInternalInaccessible" [ Error ErrorCode.InaccessibleCallable ] [] diff --git a/src/QsCompiler/Tests.Compiler/GlobalVerificationTests.fs b/src/QsCompiler/Tests.Compiler/GlobalVerificationTests.fs index 585d659e1e..e1b57eab2a 100644 --- a/src/QsCompiler/Tests.Compiler/GlobalVerificationTests.fs +++ b/src/QsCompiler/Tests.Compiler/GlobalVerificationTests.fs @@ -35,12 +35,12 @@ type GlobalVerificationTests() = this.Expect "LocalNamespaceShortNames1" [] this.Expect "LocalNamespaceShortNames2" [] this.Expect "LocalNamespaceShortNames3" [ Error ErrorCode.UnknownType ] - this.Expect "LocalNamespaceShortNames4" [ Error ErrorCode.UnknownType ] + this.Expect "LocalNamespaceShortNames4" [ Error ErrorCode.UnknownType; Warning WarningCode.DeprecatedNewArray ] this.Expect "LocalNamespaceShortNames5" [ Error ErrorCode.UnknownIdentifier ] this.Expect "LocalNamespaceShortNames6" [ Error ErrorCode.TypeMismatch; Error ErrorCode.TypeMismatch ] this.Expect "LocalNamespaceShortNames7" [ Error ErrorCode.UnknownIdentifier ] this.Expect "LocalNamespaceShortNames8" [] - this.Expect "LocalNamespaceShortNames9" [] + this.Expect "LocalNamespaceShortNames9" [ Warning WarningCode.DeprecatedNewArray ] this.Expect "LocalNamespaceShortNames10" [] this.Expect "LocalNamespaceShortNames11" [ Error ErrorCode.UnknownType; Error ErrorCode.UnknownIdentifier ] this.Expect "LocalNamespaceShortNames12" [ Error ErrorCode.UnknownIdentifier ] @@ -53,7 +53,7 @@ type GlobalVerificationTests() = this.Expect "LocalNamespaceShortNames19" [] this.Expect "LocalNamespaceShortNames20" [] this.Expect "LocalNamespaceShortNames21" [] - this.Expect "LocalNamespaceShortNames22" [] + this.Expect "LocalNamespaceShortNames22" (Warning WarningCode.DeprecatedNewArray |> List.replicate 2) this.Expect "LocalNamespaceShortNames23" [] this.Expect "LocalNamespaceShortNames24" [] @@ -533,7 +533,7 @@ type GlobalVerificationTests() = this.Expect "ValidAttributes1" [] this.Expect "ValidAttributes2" [] this.Expect "ValidAttributes3" [] - this.Expect "ValidAttributes4" [] + this.Expect "ValidAttributes4" [ Warning WarningCode.DeprecatedNewArray ] this.Expect "ValidAttributes5" [] this.Expect "ValidAttributes6" [] this.Expect "ValidAttributes7" [] @@ -555,7 +555,14 @@ type GlobalVerificationTests() = this.Expect "InvalidAttributes5" [ Error ErrorCode.UnknownTypeInNamespace ] this.Expect "InvalidAttributes6" [ Error ErrorCode.AttributeArgumentTypeMismatch ] this.Expect "InvalidAttributes7" [ Error ErrorCode.InvalidAttributeArgument ] - this.Expect "InvalidAttributes8" [ Error ErrorCode.ArgumentOfUserDefinedTypeInAttribute ] + + this.Expect + "InvalidAttributes8" + [ + Error ErrorCode.ArgumentOfUserDefinedTypeInAttribute + Warning WarningCode.DeprecatedNewArray + ] + this.Expect "InvalidAttributes9" [ Error ErrorCode.MisplacedDeclarationAttribute ] this.Expect "InvalidAttributes10" [ Error ErrorCode.MisplacedDeclarationAttribute ] this.Expect "InvalidAttributes11" [ Error ErrorCode.MisplacedDeclarationAttribute ] diff --git a/src/QsCompiler/Tests.Compiler/LocalVerificationTests.fs b/src/QsCompiler/Tests.Compiler/LocalVerificationTests.fs index 58a0245e11..a3d0273f10 100644 --- a/src/QsCompiler/Tests.Compiler/LocalVerificationTests.fs +++ b/src/QsCompiler/Tests.Compiler/LocalVerificationTests.fs @@ -47,25 +47,25 @@ type LocalVerificationTests() = this.Expect "TypeArgumentsInference6" [] this.Expect "TypeArgumentsInference7" [] - this.Expect "TypeArgumentsInference8" [] - this.Expect "TypeArgumentsInference9" [] + this.Expect "TypeArgumentsInference8" [ Warning WarningCode.DeprecatedNewArray ] + this.Expect "TypeArgumentsInference9" [ Warning WarningCode.DeprecatedNewArray ] this.Expect "TypeArgumentsInference10" [] this.Expect "TypeArgumentsInference11" [] this.Expect "TypeArgumentsInference12" [] this.Expect "TypeArgumentsInference13" [] this.Expect "TypeArgumentsInference14" [] this.Expect "TypeArgumentsInference15" [] - this.Expect "TypeArgumentsInference16" [] - this.Expect "TypeArgumentsInference17" [] - this.Expect "TypeArgumentsInference18" [] + this.Expect "TypeArgumentsInference16" [ Warning WarningCode.DeprecatedNewArray ] + this.Expect "TypeArgumentsInference17" [ Warning WarningCode.DeprecatedNewArray ] + this.Expect "TypeArgumentsInference18" [ Warning WarningCode.DeprecatedNewArray ] this.Expect "TypeArgumentsInference19" [] this.Expect "TypeArgumentsInference20" [] this.Expect "TypeArgumentsInference21" [ Error ErrorCode.TypeMismatch ] this.Expect "TypeArgumentsInference22" [ Error ErrorCode.TypeMismatch ] this.Expect "TypeArgumentsInference23" [] this.Expect "TypeArgumentsInference24" [] - this.Expect "TypeArgumentsInference25" [] - this.Expect "TypeArgumentsInference26" [] + this.Expect "TypeArgumentsInference25" [ Warning WarningCode.DeprecatedNewArray ] + this.Expect "TypeArgumentsInference26" [ Warning WarningCode.DeprecatedNewArray ] this.Expect "TypeArgumentsInference27" [ Error ErrorCode.TypeMismatch ] this.Expect "TypeArgumentsInference28" [ Error ErrorCode.TypeMismatch ] this.Expect "TypeArgumentsInference29" [ Error ErrorCode.InvalidCyclicTypeParameterResolution ] @@ -88,8 +88,8 @@ type LocalVerificationTests() = this.Expect "TypeArgumentsInference33" [ Error ErrorCode.TypeMismatch ] this.Expect "TypeArgumentsInference34" [] this.Expect "TypeArgumentsInference35" [] - this.Expect "TypeArgumentsInference36" [] - this.Expect "TypeArgumentsInference37" [] + this.Expect "TypeArgumentsInference36" [ Warning WarningCode.DeprecatedNewArray ] + this.Expect "TypeArgumentsInference37" [ Warning WarningCode.DeprecatedNewArray ] this.Expect "TypeArgumentsInference38" [ Error ErrorCode.TypeMismatch ] this.Expect "TypeArgumentsInference39" [ Error ErrorCode.TypeMismatch ] this.Expect "TypeArgumentsInference40" [] @@ -134,10 +134,10 @@ type LocalVerificationTests() = this.Expect "VariableDeclaration15" [] this.Expect "VariableDeclaration16" [] - this.Expect "VariableDeclaration17" [] - this.Expect "VariableDeclaration18" [] - this.Expect "VariableDeclaration19" [] - this.Expect "VariableDeclaration20" [] + this.Expect "VariableDeclaration17" [ Warning WarningCode.DeprecatedNewArray ] + this.Expect "VariableDeclaration18" [ Warning WarningCode.DeprecatedNewArray ] + this.Expect "VariableDeclaration19" [ Warning WarningCode.DeprecatedNewArray ] + this.Expect "VariableDeclaration20" [ Warning WarningCode.DeprecatedNewArray ] this.Expect "VariableDeclaration21" [] this.Expect "VariableDeclaration22" [] this.Expect "VariableDeclaration23" [] @@ -157,7 +157,7 @@ type LocalVerificationTests() = this.Expect "CopyAndUpdateArray1" [] this.Expect "CopyAndUpdateArray2" [] this.Expect "CopyAndUpdateArray3" [] - this.Expect "CopyAndUpdateArray4" [] + this.Expect "CopyAndUpdateArray4" [ Warning WarningCode.DeprecatedNewArray ] this.Expect "CopyAndUpdateArray5" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ] this.Expect "CopyAndUpdateArray6" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ] this.Expect "CopyAndUpdateArray7" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ] @@ -179,11 +179,23 @@ type LocalVerificationTests() = this.Expect "UpdateAndReassign3" [] this.Expect "UpdateAndReassign4" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ] this.Expect "UpdateAndReassign5" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ] - this.Expect "UpdateAndReassign6" [] - this.Expect "UpdateAndReassign7" [] - this.Expect "UpdateAndReassign8" [] - this.Expect "UpdateAndReassign9" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ] - this.Expect "UpdateAndReassign10" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ] + this.Expect "UpdateAndReassign6" [ Warning WarningCode.DeprecatedNewArray ] + this.Expect "UpdateAndReassign7" [ Warning WarningCode.DeprecatedNewArray ] + this.Expect "UpdateAndReassign8" [ Warning WarningCode.DeprecatedNewArray ] + + this.Expect + "UpdateAndReassign9" + [ + Error ErrorCode.TypeMismatchInCopyAndUpdateExpr + Warning WarningCode.DeprecatedNewArray + ] + + this.Expect + "UpdateAndReassign10" + [ + Error ErrorCode.TypeMismatchInCopyAndUpdateExpr + Warning WarningCode.DeprecatedNewArray + ] [] @@ -234,7 +246,7 @@ type LocalVerificationTests() = this.Expect "ItemAccess16" [] this.Expect "ItemAccess17" [] this.Expect "ItemAccess18" [] - this.Expect "ItemAccess19" [] + this.Expect "ItemAccess19" [ Warning WarningCode.DeprecatedNewArray ] this.Expect "ItemAccess20" [] @@ -255,22 +267,29 @@ type LocalVerificationTests() = Error ErrorCode.TypeMismatchInCopyAndUpdateExpr ] - this.Expect "ItemUpdate9" [] + this.Expect "ItemUpdate9" [ Warning WarningCode.DeprecatedNewArray ] this.Expect "ItemUpdate10" [ Error ErrorCode.InvalidIdentifierExprInUpdate Error ErrorCode.ExcessContinuation + Warning WarningCode.DeprecatedNewArray ] - this.Expect "ItemUpdate11" [ Error ErrorCode.UpdateOfArrayItemExpr ] + this.Expect + "ItemUpdate11" + [ + Error ErrorCode.UpdateOfArrayItemExpr + Warning WarningCode.DeprecatedNewArray + ] this.Expect "ItemUpdate12" [ Error ErrorCode.TypeMismatchInCopyAndUpdateExpr Error ErrorCode.TypeMismatchInCopyAndUpdateExpr + Warning WarningCode.DeprecatedNewArray ] this.Expect "ItemUpdate13" [] @@ -294,7 +313,7 @@ type LocalVerificationTests() = this.Expect "ItemUpdate18" [ Error ErrorCode.MissingFunctorForAutoGeneration ] this.Expect "ItemUpdate19" [ Error ErrorCode.MissingFunctorForAutoGeneration ] this.Expect "ItemUpdate20" [] - this.Expect "ItemUpdate21" [] + this.Expect "ItemUpdate21" [ Warning WarningCode.DeprecatedNewArray ] this.Expect "ItemUpdate22" [] @@ -374,7 +393,13 @@ type LocalVerificationTests() = this.Expect "UsingDepAttrInDepCall" [ Warning WarningCode.DeprecationWithoutRedirect ] this.Expect "UsingDepTypeInDepCall" [ Warning WarningCode.DeprecationWithoutRedirect ] - this.Expect "UsingDeprecatedType1" [ Warning WarningCode.DeprecationWithoutRedirect ] + this.Expect + "UsingDeprecatedType1" + [ + Warning WarningCode.DeprecationWithoutRedirect + Warning WarningCode.DeprecatedNewArray + ] + this.Expect "UsingDeprecatedType2" [ Warning WarningCode.DeprecationWithoutRedirect ] this.Expect "UsingDeprecatedType3" [ Warning WarningCode.DeprecationWithoutRedirect ] @@ -392,7 +417,13 @@ type LocalVerificationTests() = Warning WarningCode.DeprecationWithoutRedirect ] - this.Expect "UsingRenamedType1" [ Warning WarningCode.DeprecationWithRedirect ] + this.Expect + "UsingRenamedType1" + [ + Warning WarningCode.DeprecationWithRedirect + Warning WarningCode.DeprecatedNewArray + ] + this.Expect "UsingRenamedType2" [ Warning WarningCode.DeprecationWithRedirect ] this.Expect "UsingRenamedType3" [ Warning WarningCode.DeprecationWithRedirect ] diff --git a/src/QsCompiler/Tests.Compiler/SyntaxTests.fs b/src/QsCompiler/Tests.Compiler/SyntaxTests.fs index 4c5b8ffb63..816440e452 100644 --- a/src/QsCompiler/Tests.Compiler/SyntaxTests.fs +++ b/src/QsCompiler/Tests.Compiler/SyntaxTests.fs @@ -889,12 +889,16 @@ let ``Function type tests`` () = "new (Int -> Int)[0]", true, toNewArray (toTupleType [ Function(toType Int, toType Int) |> toType ]) (toInt 0), - [] + [ Warning WarningCode.DeprecatedNewArray ] "new Int -> Int[0]", true, toNewArray (Function(toType Int, toType Int) |> toType) (toInt 0), - [ Error ErrorCode.MissingLTupleBracket; Error ErrorCode.MissingRTupleBracket ] + [ + Error ErrorCode.MissingLTupleBracket + Error ErrorCode.MissingRTupleBracket + Warning WarningCode.DeprecatedNewArray + ] ] |> List.iter testExpr @@ -986,45 +990,86 @@ let ``Operation type tests`` () = "new (Qubit => Unit is Adj)[0]", true, toNewArray (toTupleType [ toOpType qubitType unitType adjSet ]) (toInt 0), - [] + [ Warning WarningCode.DeprecatedNewArray ] "new Qubit => Unit is Adj[0]", true, toNewArray (toOpType qubitType unitType adjSet) (toInt 0), - [ Error ErrorCode.MissingLTupleBracket; Error ErrorCode.MissingRTupleBracket ] + [ + Error ErrorCode.MissingLTupleBracket + Error ErrorCode.MissingRTupleBracket + Warning WarningCode.DeprecatedNewArray + ] - "new (Qubit => Unit) is Adj[0]", true, toExpr InvalidExpr, [ Error ErrorCode.InvalidConstructorExpression ] + "new (Qubit => Unit) is Adj[0]", + true, + toExpr InvalidExpr, + [ + Error ErrorCode.InvalidConstructorExpression + Warning WarningCode.DeprecatedNewArray + ] "new (Qubit => Unit : Adjoint)[0]", true, toNewArray (toTupleType [ toOpType qubitType unitType emptySet ]) (toInt 0), - [ Error ErrorCode.ExcessContinuation ] + [ Error ErrorCode.ExcessContinuation; Warning WarningCode.DeprecatedNewArray ] - "new Qubit => Unit : Adjoint[0]", true, toExpr InvalidExpr, [ Error ErrorCode.InvalidConstructorExpression ] - "new (Qubit => Unit) : Adjoint[0]", true, toExpr InvalidExpr, [ Error ErrorCode.InvalidConstructorExpression ] + "new Qubit => Unit : Adjoint[0]", + true, + toExpr InvalidExpr, + [ + Error ErrorCode.InvalidConstructorExpression + Warning WarningCode.DeprecatedNewArray + ] + "new (Qubit => Unit) : Adjoint[0]", + true, + toExpr InvalidExpr, + [ + Error ErrorCode.InvalidConstructorExpression + Warning WarningCode.DeprecatedNewArray + ] "new (Qubit => Unit : Adj)[0]", true, toNewArray (toTupleType [ toOpType qubitType unitType emptySet ]) (toInt 0), - [ Error ErrorCode.ExcessContinuation ] + [ Error ErrorCode.ExcessContinuation; Warning WarningCode.DeprecatedNewArray ] - "new Qubit => Unit : Adj[0]", true, toExpr InvalidExpr, [ Error ErrorCode.InvalidConstructorExpression ] - "new (Qubit => Unit) : Adj[0]", true, toExpr InvalidExpr, [ Error ErrorCode.InvalidConstructorExpression ] + "new Qubit => Unit : Adj[0]", + true, + toExpr InvalidExpr, + [ + Error ErrorCode.InvalidConstructorExpression + Warning WarningCode.DeprecatedNewArray + ] + "new (Qubit => Unit) : Adj[0]", + true, + toExpr InvalidExpr, + [ + Error ErrorCode.InvalidConstructorExpression + Warning WarningCode.DeprecatedNewArray + ] "new (Qubit => Unit is Adj + Ctl)[0]", true, toNewArray (toTupleType [ toOpType qubitType unitType adjCtlSet ]) (toInt 0), - [] + [ Warning WarningCode.DeprecatedNewArray ] "new Qubit => Unit is Adj + Ctl[0]", true, toNewArray (toOpType qubitType unitType adjCtlSet) (toInt 0), - [ Error ErrorCode.MissingLTupleBracket; Error ErrorCode.MissingRTupleBracket ] + [ + Error ErrorCode.MissingLTupleBracket + Error ErrorCode.MissingRTupleBracket + Warning WarningCode.DeprecatedNewArray + ] "new (Qubit => Unit) is Adj + Ctl[0]", true, toExpr InvalidExpr, - [ Error ErrorCode.InvalidConstructorExpression ] + [ + Error ErrorCode.InvalidConstructorExpression + Warning WarningCode.DeprecatedNewArray + ] "new (Qubit => Unit : Adjoint, Controlled)[0]", true, @@ -1032,25 +1077,47 @@ let ``Operation type tests`` () = (toTupleType [ toOpType qubitType unitType emptySet toType InvalidType ]) (toInt 0), - [ Error ErrorCode.ExcessContinuation; Error ErrorCode.InvalidType ] + [ + Error ErrorCode.ExcessContinuation + Error ErrorCode.InvalidType + Warning WarningCode.DeprecatedNewArray + ] "new Qubit => Unit : Adjoint, Controlled[0]", true, toExpr InvalidExpr, - [ Error ErrorCode.InvalidConstructorExpression ] + [ + Error ErrorCode.InvalidConstructorExpression + Warning WarningCode.DeprecatedNewArray + ] "new (Qubit => Unit) : Adjoint, Controlled[0]", true, toExpr InvalidExpr, - [ Error ErrorCode.InvalidConstructorExpression ] + [ + Error ErrorCode.InvalidConstructorExpression + Warning WarningCode.DeprecatedNewArray + ] "new (Qubit => Unit : Adj + Ctl)[0]", true, toNewArray (toTupleType [ toOpType qubitType unitType emptySet ]) (toInt 0), - [ Error ErrorCode.ExcessContinuation ] + [ Error ErrorCode.ExcessContinuation; Warning WarningCode.DeprecatedNewArray ] - "new Qubit => Unit : Adj + Ctl[0]", true, toExpr InvalidExpr, [ Error ErrorCode.InvalidConstructorExpression ] - "new (Qubit => Unit) : Adj + Ctl[0]", true, toExpr InvalidExpr, [ Error ErrorCode.InvalidConstructorExpression ] + "new Qubit => Unit : Adj + Ctl[0]", + true, + toExpr InvalidExpr, + [ + Error ErrorCode.InvalidConstructorExpression + Warning WarningCode.DeprecatedNewArray + ] + "new (Qubit => Unit) : Adj + Ctl[0]", + true, + toExpr InvalidExpr, + [ + Error ErrorCode.InvalidConstructorExpression + Warning WarningCode.DeprecatedNewArray + ] "new (Qubit => Unit : Adj, Ctl)[0]", true, @@ -1058,10 +1125,26 @@ let ``Operation type tests`` () = (toTupleType [ toOpType qubitType unitType emptySet toType InvalidType ]) (toInt 0), - [ Error ErrorCode.ExcessContinuation; Error ErrorCode.InvalidType ] + [ + Error ErrorCode.ExcessContinuation + Error ErrorCode.InvalidType + Warning WarningCode.DeprecatedNewArray + ] - "new Qubit => Unit : Adj, Ctl[0]", true, toExpr InvalidExpr, [ Error ErrorCode.InvalidConstructorExpression ] - "new (Qubit => Unit) : Adj, Ctl[0]", true, toExpr InvalidExpr, [ Error ErrorCode.InvalidConstructorExpression ] + "new Qubit => Unit : Adj, Ctl[0]", + true, + toExpr InvalidExpr, + [ + Error ErrorCode.InvalidConstructorExpression + Warning WarningCode.DeprecatedNewArray + ] + "new (Qubit => Unit) : Adj, Ctl[0]", + true, + toExpr InvalidExpr, + [ + Error ErrorCode.InvalidConstructorExpression + Warning WarningCode.DeprecatedNewArray + ] "new (Qubit => Unit is Adj, Ctl)[0]", true, @@ -1069,50 +1152,68 @@ let ``Operation type tests`` () = (toTupleType [ toOpType qubitType unitType adjSet toType InvalidType ]) (toInt 0), - [ Error ErrorCode.InvalidType ] + [ Error ErrorCode.InvalidType; Warning WarningCode.DeprecatedNewArray ] - "new Qubit => Unit is Adj, Ctl[0]", true, toExpr InvalidExpr, [ Error ErrorCode.InvalidConstructorExpression ] - "new (Qubit => Unit) is Adj, Ctl[0]", true, toExpr InvalidExpr, [ Error ErrorCode.InvalidConstructorExpression ] + "new Qubit => Unit is Adj, Ctl[0]", + true, + toExpr InvalidExpr, + [ + Error ErrorCode.InvalidConstructorExpression + Warning WarningCode.DeprecatedNewArray + ] + "new (Qubit => Unit) is Adj, Ctl[0]", + true, + toExpr InvalidExpr, + [ + Error ErrorCode.InvalidConstructorExpression + Warning WarningCode.DeprecatedNewArray + ] "new (Qubit => Unit is (Adj + Ctl))[0]", true, toNewArray (toTupleType [ toOpType qubitType unitType adjCtlSet ]) (toInt 0), - [] + [ Warning WarningCode.DeprecatedNewArray ] "new (Qubit => Unit is ((Adj) + (Ctl)))[0]", true, toNewArray (toTupleType [ toOpType qubitType unitType adjCtlSet ]) (toInt 0), - [] + [ Warning WarningCode.DeprecatedNewArray ] "new (Qubit => Unit is (Adj + Ctl _))[0]", true, toNewArray (toTupleType [ toOpType qubitType unitType adjCtlSet ]) (toInt 0), - [ Error ErrorCode.ExcessContinuation ] + [ Error ErrorCode.ExcessContinuation; Warning WarningCode.DeprecatedNewArray ] "new (Qubit => Unit is ())[0]", true, toNewArray (toTupleType [ toOpType qubitType unitType (toCharacteristicsExpr InvalidSetExpr) ]) (toInt 0), - [ Error ErrorCode.MissingOperationCharacteristics ] + [ + Error ErrorCode.MissingOperationCharacteristics + Warning WarningCode.DeprecatedNewArray + ] "new (Qubit => Unit is (Adj + (Ctl + )))[0]", true, toNewArray (toTupleType [ toOpType qubitType unitType (toCharacteristicsExpr InvalidSetExpr) ]) (toInt 0), - [ Error ErrorCode.InvalidOperationCharacteristics ] + [ + Error ErrorCode.InvalidOperationCharacteristics + Warning WarningCode.DeprecatedNewArray + ] "new (Qubit => Unit is MySet)[0]", true, toNewArray (toTupleType [ toOpType qubitType unitType (toCharacteristicsExpr InvalidSetExpr) ]) (toInt 0), - [ Error ErrorCode.UnknownSetName ] + [ Error ErrorCode.UnknownSetName; Warning WarningCode.DeprecatedNewArray ] "new (Qubit => Unit is Adj + MySet)[0]", true, toNewArray (toTupleType [ toOpType qubitType unitType (toCharacteristicsExpr InvalidSetExpr) ]) (toInt 0), - [ Error ErrorCode.UnknownSetName ] + [ Error ErrorCode.UnknownSetName; Warning WarningCode.DeprecatedNewArray ] "new (Qubit => Unit is (Adj + MySet))[0]", true, toNewArray (toTupleType [ toOpType qubitType unitType (toCharacteristicsExpr InvalidSetExpr) ]) (toInt 0), - [ Error ErrorCode.UnknownSetName ] + [ Error ErrorCode.UnknownSetName; Warning WarningCode.DeprecatedNewArray ] ] |> List.iter testExpr diff --git a/src/QsCompiler/Tests.Compiler/TestCases/ExecutionTests/LoggingBasedTests.qs b/src/QsCompiler/Tests.Compiler/TestCases/ExecutionTests/LoggingBasedTests.qs index d07ed13cb6..8404ec6fc9 100644 --- a/src/QsCompiler/Tests.Compiler/TestCases/ExecutionTests/LoggingBasedTests.qs +++ b/src/QsCompiler/Tests.Compiler/TestCases/ExecutionTests/LoggingBasedTests.qs @@ -25,7 +25,7 @@ namespace Microsoft.Quantum.Testing.ExecutionTests { // tests related to auto-generation of functor specializations for operations involving conjugations - operation SpecGenForConjugations () : Unit + operation SpecGenForConjugations () : Unit is Adj + Ctl { within { @@ -64,11 +64,11 @@ namespace Microsoft.Quantum.Testing.ExecutionTests { } operation ConjugationsInControlled () : Unit { - Controlled SpecGenForConjugations(new Qubit[0], ()); + Controlled SpecGenForConjugations([], ()); } operation ConjugationsInControlledAdjoint () : Unit { - Controlled Adjoint SpecGenForConjugations(new Qubit[0], ()); + Controlled Adjoint SpecGenForConjugations([], ()); } diff --git a/src/QsCompiler/Tests.Compiler/TestCases/ExecutionTests/Packaging.qs b/src/QsCompiler/Tests.Compiler/TestCases/ExecutionTests/Packaging.qs index f7c979ad95..6451b1673a 100644 --- a/src/QsCompiler/Tests.Compiler/TestCases/ExecutionTests/Packaging.qs +++ b/src/QsCompiler/Tests.Compiler/TestCases/ExecutionTests/Packaging.qs @@ -1,20 +1,17 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -namespace Microsoft.Quantum.Testing.ExecutionTests -{ +namespace Microsoft.Quantum.Testing.ExecutionTests { open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Testing; - operation PackageAndProjectReference () : Unit { Message("Welcome to Q#!"); Log(1, "Go check out https://docs.microsoft.com/azure/quantum."); } operation TypeInReferencedProject () : Unit { - mutable arr = new Complex[1]; - set arr w/= 0 <- Complex(1.,0.); + let arr = [Complex(1., 0.)]; Message($"{arr}"); } } diff --git a/src/QsCompiler/Tests.Compiler/TestCases/FunctorGeneration.qs b/src/QsCompiler/Tests.Compiler/TestCases/FunctorGeneration.qs index ea5f174b11..f2966fca7f 100644 --- a/src/QsCompiler/Tests.Compiler/TestCases/FunctorGeneration.qs +++ b/src/QsCompiler/Tests.Compiler/TestCases/FunctorGeneration.qs @@ -156,14 +156,14 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { operation ControlledAdjointGenDirective10 (q : Qubit) : Unit { body (...) { } adjoint (...) { } - controlled adjoint self; + controlled adjoint self; controlled auto; } operation ControlledAdjointGenDirective11 (q : Qubit) : Unit { body (...) { } adjoint invert; - controlled adjoint self; + controlled adjoint self; controlled auto; } @@ -291,30 +291,30 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { // checking that functor support is verified for local variables and partial application as well operation VariableNeedsFunctorSupport1 (q : Qubit) : Unit { - body (...) { + body (...) { let op = Controllable; - op(q); + op(q); } adjoint auto; } operation VariableNeedsFunctorSupport2 (q : Qubit) : Unit { - body (...) { + body (...) { let op = Adjointable; - op(q); + op(q); } controlled auto; } operation VariableNeedsFunctorSupport3 (q : Qubit) : Unit { - body (...) { + body (...) { (Controllable(_))(q); } adjoint auto; } operation VariableNeedsFunctorSupport4 (q : Qubit) : Unit { - body (...) { + body (...) { (Adjointable(_))(q); } controlled auto; @@ -322,30 +322,30 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { operation VariableWithFunctorSupport1 (q : Qubit) : Unit { - body (...) { + body (...) { let op = Controllable; - op(q); + op(q); } controlled auto; } operation VariableWithFunctorSupport2 (q : Qubit) : Unit { - body (...) { + body (...) { let op = Adjointable; - op(q); + op(q); } adjoint auto; } operation VariableWithFunctorSupport3 (q : Qubit) : Unit { - body (...) { + body (...) { (Controllable(_))(q); } controlled auto; } operation VariableWithFunctorSupport4 (q : Qubit) : Unit { - body (...) { + body (...) { (Adjointable(_))(q); } adjoint auto; @@ -401,7 +401,7 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { } operation NeedsFunctorSupport10 (q : Qubit) : Unit { - body (...) { + body (...) { within { Controllable(q); } apply {} } @@ -409,7 +409,7 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { } operation NeedsFunctorSupport11 (q : Qubit) : Unit { - body (...) { + body (...) { within { } apply { Operation(q); } } @@ -417,7 +417,7 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { } operation NeedsFunctorSupport12 (q : Qubit) : Unit { - body (...) { + body (...) { within { } apply { Operation(q); } } @@ -425,7 +425,7 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { } operation NeedsFunctorSupport13 (q : Qubit) : Unit { - body (...) { + body (...) { within { } apply { Controllable(q); } } @@ -445,7 +445,7 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { operation NeedsFunctorSupport16(q : Qubit) : Unit { body (...) { within { Operation(q); } - apply { } + apply { } } adjoint self; } @@ -453,7 +453,7 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { operation NeedsFunctorSupport17(q : Qubit) : Unit is Adj { within { Controllable(q); } - apply { } + apply { } } @@ -520,7 +520,7 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { } operation FunctorSupport13 (q : Qubit) : Unit { - body (...) { + body (...) { within { Adjointable(q); } apply {} } @@ -528,7 +528,7 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { } operation FunctorSupport14 (q : Qubit) : Unit { - body (...) { + body (...) { within { Adjointable(q); } apply {} } @@ -536,7 +536,7 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { } operation FunctorSupport15 (q : Qubit) : Unit { - body (...) { + body (...) { within {} apply { Operation(q); } } @@ -614,9 +614,9 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { operation InvalidAutoInversion1(q : Qubit) : Unit { body (...) { - return (); + return (); } - adjoint auto; + adjoint auto; } operation InvalidAutoInversion2(q : Qubit) : Unit { @@ -625,21 +625,21 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { until (true) fixup {} } - adjoint auto; + adjoint auto; } operation InvalidAutoInversion3(q : Qubit) : Unit { body (...) { set _ = 1; } - adjoint auto; + adjoint auto; } operation InvalidAutoInversion4(q : Qubit) : Unit { body (...) { if (true) { return (); } } - adjoint auto; + adjoint auto; } operation InvalidAutoInversion5(q : Qubit) : Unit { @@ -650,21 +650,21 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { fixup {} } } - adjoint auto; + adjoint auto; } operation InvalidAutoInversion6(q : Qubit) : Unit { body (...) { if (true) { set _ = 1; } } - adjoint auto; + adjoint auto; } operation InvalidAutoInversion7(q : Qubit) : Unit { body (...) { for i in 1..10 { return (); } } - adjoint auto; + adjoint auto; } operation InvalidAutoInversion8(q : Qubit) : Unit { @@ -675,21 +675,21 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { fixup {} } } - adjoint auto; + adjoint auto; } operation InvalidAutoInversion9(q : Qubit) : Unit { body (...) { for i in 1..10 { set _ = 1; } } - adjoint auto; + adjoint auto; } operation InvalidAutoInversion10(q : Qubit) : Unit { body (...) { use c = Qubit() { return (); } } - adjoint auto; + adjoint auto; } operation InvalidAutoInversion11(q : Qubit) : Unit { @@ -700,21 +700,21 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { fixup {} } } - adjoint auto; + adjoint auto; } operation InvalidAutoInversion12(q : Qubit) : Unit { body (...) { use c = Qubit() { set _ = 1; } } - adjoint auto; + adjoint auto; } operation InvalidAutoInversion13(q : Qubit) : Unit { body (...) { borrow c = Qubit() { return (); } } - adjoint auto; + adjoint auto; } operation InvalidAutoInversion14(q : Qubit) : Unit { @@ -725,14 +725,14 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { fixup {} } } - adjoint auto; + adjoint auto; } operation InvalidAutoInversion15(q : Qubit) : Unit { body (...) { borrow c = Qubit() { set _ = 1; } } - adjoint auto; + adjoint auto; } operation InvalidAutoInversion16(q : Qubit) : Unit { @@ -756,7 +756,7 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { operation ValidInversion1(q : Qubit) : Unit { body (...) { - return (); + return (); } adjoint self; } @@ -767,7 +767,7 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { until (true) fixup {} } - adjoint self; + adjoint self; } operation ValidInversion3(q : Qubit) : Unit { @@ -775,15 +775,15 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { mutable foo = 0; set foo = 1; } - adjoint self; + adjoint self; } operation ValidInversion4(q : Qubit) : Unit { body (...) { - // NOTE: this is ok because, opposed to a return-statement, + // NOTE: this is ok because, opposed to a return-statement, // there is no way modify control flow in a meaningful way using a fail // (the computation fails either way albeit potentially a bit earlier rather than later) - fail "not yet implemented"; + fail "not yet implemented"; } adjoint auto; } @@ -848,7 +848,7 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { operation WithInvalidQuantumDependency5 (q : Qubit) : Unit { body (...) { - for i in CoinFlip() ? new Int[0] | new Int[1] {} + for i in CoinFlip() ? [] | [0] {} } adjoint auto; } @@ -929,7 +929,7 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { operation InvalidControlled2 (q : Qubit) : Unit { body (...) { - for i in CoinFlip() ? new Int[0] | new Int[1] {} + for i in CoinFlip() ? [] | [0] {} } controlled auto; } @@ -951,42 +951,42 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { operation ValidControlled1 (q : Qubit) : Unit { body (...) { - let _ = Controllable (q); + let _ = Controllable (q); } controlled auto; } operation ValidControlled2 (q : Qubit) : Unit { body (...) { - mutable _ = Controllable (q); + mutable _ = Controllable (q); } controlled auto; } operation ValidControlled3 (q : Qubit) : Unit { body (...) { - set _ = Controllable (q); + set _ = Controllable (q); } controlled auto; } operation ValidControlled4 (q : Qubit) : Unit { body (...) { - return Controllable(q); + return Controllable(q); } controlled auto; } operation ValidControlled5 (q : Qubit) : Unit { body (...) { - fail $"{Controllable (q)}"; + fail $"{Controllable (q)}"; } controlled auto; } operation ValidControlled6 (q : Qubit) : Unit { body (...) { - if (true) { Controllable(q); } + if (true) { Controllable(q); } } controlled auto; } @@ -1063,7 +1063,7 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { controlled auto; controlled adjoint invert; } - + operation ValidControlledAdjointGeneration1 (q : Qubit) : Unit { body (...) { Operation (q); } @@ -1194,51 +1194,51 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { operation AutoAdjSpec () : Unit { - adjoint auto; + adjoint auto; } operation InvertAdjSpec () : Unit { - adjoint invert; + adjoint invert; } operation SelfAdjSpec () : Unit { - adjoint self; + adjoint self; } operation AutoCtlSpec () : Unit { controlled auto; - } + } operation DistrCtlSpec () : Unit { - controlled distribute; + controlled distribute; } operation CtlAffAutoAdjSpec () : Unit is Ctl { - adjoint auto; + adjoint auto; } operation CtlAffInvertAdjSpec () : Unit is Ctl { - adjoint invert; + adjoint invert; } operation CtlAffSelfAdjSpec () : Unit is Ctl { - adjoint self; + adjoint self; } operation AdjAffAutoCtlSpec () : Unit is Adj { controlled auto; - } + } operation AdjAffDistrCtlSpec () : Unit is Adj { - controlled distribute; + controlled distribute; } // operation characteristics expressions operation OperationCharacteristics1 (qs : Qubit[]) : Unit { - NoAffiliation(); - AdjAffiliation(); + NoAffiliation(); + AdjAffiliation(); CtlAffiliation(); CtlAdjAffiliation(); AdjCtlAffiliation(); @@ -1251,96 +1251,96 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { Adjoint AdjCtlAffiliation(); Adjoint AdjViaIntersection(); Controlled CtlAffiliation(qs, ()); - Controlled CtlAdjAffiliation(qs, ()); - Controlled AdjCtlAffiliation(qs, ()); - Controlled CtlViaIntersection(qs, ()); + Controlled CtlAdjAffiliation(qs, ()); + Controlled AdjCtlAffiliation(qs, ()); + Controlled CtlViaIntersection(qs, ()); } operation OperationCharacteristics2 (qs : Qubit[]) : Unit { - Adjoint NoAffiliation(); + Adjoint NoAffiliation(); } operation OperationCharacteristics3 (qs : Qubit[]) : Unit { - Controlled NoAffiliation((), qs); + Controlled NoAffiliation((), qs); } operation OperationCharacteristics4 (qs : Qubit[]) : Unit { - Controlled AdjAffiliation((), qs); + Controlled AdjAffiliation((), qs); } operation OperationCharacteristics5 (qs : Qubit[]) : Unit { - Adjoint CtlAffiliation(); + Adjoint CtlAffiliation(); } operation OperationCharacteristics6 (qs : Qubit[]) : Unit { - Adjoint AdjCtlIntersection(); + Adjoint AdjCtlIntersection(); } operation OperationCharacteristics7 (qs : Qubit[]) : Unit { - Adjoint CtlAdjIntersection(); + Adjoint CtlAdjIntersection(); } operation OperationCharacteristics8 (qs : Qubit[]) : Unit { - Adjoint CtlViaIntersection(); + Adjoint CtlViaIntersection(); } operation OperationCharacteristics9 (qs : Qubit[]) : Unit { - Controlled AdjCtlIntersection(qs, ()); + Controlled AdjCtlIntersection(qs, ()); } operation OperationCharacteristics10 (qs : Qubit[]) : Unit { - Controlled CtlAdjIntersection(qs, ()); + Controlled CtlAdjIntersection(qs, ()); } operation OperationCharacteristics11 (qs : Qubit[]) : Unit { - Controlled AdjViaIntersection(qs, ()); + Controlled AdjViaIntersection(qs, ()); } operation OperationCharacteristics12 (qs : Qubit[]) : Unit { - Adjoint EmptyIntersection1(); + Adjoint EmptyIntersection1(); } operation OperationCharacteristics13 (qs : Qubit[]) : Unit { - Adjoint EmptyIntersection2(); + Adjoint EmptyIntersection2(); } operation OperationCharacteristics14 (qs : Qubit[]) : Unit { - Controlled EmptyIntersection1(qs, ()); + Controlled EmptyIntersection1(qs, ()); } operation OperationCharacteristics15 (qs : Qubit[]) : Unit { - Controlled EmptyIntersection2(qs, ()); + Controlled EmptyIntersection2(qs, ()); } operation OperationCharacteristics16 (qs : Qubit[]) : Unit { - CtlAffAutoAdjSpec(); - CtlAffInvertAdjSpec(); + CtlAffAutoAdjSpec(); + CtlAffInvertAdjSpec(); CtlAffSelfAdjSpec(); Adjoint CtlAffAutoAdjSpec(); Adjoint CtlAffInvertAdjSpec(); Adjoint CtlAffSelfAdjSpec(); - Controlled CtlAffAutoAdjSpec(qs, ()); - Controlled CtlAffInvertAdjSpec(qs, ()); - Controlled CtlAffSelfAdjSpec(qs, ()); + Controlled CtlAffAutoAdjSpec(qs, ()); + Controlled CtlAffInvertAdjSpec(qs, ()); + Controlled CtlAffSelfAdjSpec(qs, ()); } operation OperationCharacteristics17 (qs : Qubit[]) : Unit { - AdjAffAutoCtlSpec(); + AdjAffAutoCtlSpec(); AdjAffDistrCtlSpec(); Adjoint AdjAffAutoCtlSpec(); Adjoint AdjAffDistrCtlSpec(); - Controlled AdjAffAutoCtlSpec(qs, ()); - Controlled AdjAffDistrCtlSpec(qs, ()); + Controlled AdjAffAutoCtlSpec(qs, ()); + Controlled AdjAffDistrCtlSpec(qs, ()); } operation OperationCharacteristics18 (qs : Qubit[]) : Unit { - AutoCtlSpec(); + AutoCtlSpec(); DistrCtlSpec(); - AutoAdjSpec(); - InvertAdjSpec(); + AutoAdjSpec(); + InvertAdjSpec(); SelfAdjSpec(); - Controlled AutoCtlSpec(qs, ()); - Controlled DistrCtlSpec(qs, ()); + Controlled AutoCtlSpec(qs, ()); + Controlled DistrCtlSpec(qs, ()); Adjoint AutoAdjSpec(); Adjoint InvertAdjSpec(); Adjoint SelfAdjSpec(); @@ -1355,15 +1355,15 @@ namespace Microsoft.Quantum.Testing.FunctorGeneration { } operation OperationCharacteristics21 (qs : Qubit[]) : Unit { - Controlled AutoAdjSpec(qs, ()); + Controlled AutoAdjSpec(qs, ()); } operation OperationCharacteristics22 (qs : Qubit[]) : Unit { - Controlled InvertAdjSpec(qs, ()); + Controlled InvertAdjSpec(qs, ()); } operation OperationCharacteristics23 (qs : Qubit[]) : Unit { - Controlled SelfAdjSpec(qs, ()); + Controlled SelfAdjSpec(qs, ()); } } diff --git a/src/QsCompiler/Tests.Compiler/TestCases/LocalVerification.qs b/src/QsCompiler/Tests.Compiler/TestCases/LocalVerification.qs index ae83d16960..d0f34986e2 100644 --- a/src/QsCompiler/Tests.Compiler/TestCases/LocalVerification.qs +++ b/src/QsCompiler/Tests.Compiler/TestCases/LocalVerification.qs @@ -43,13 +43,13 @@ namespace Microsoft.Quantum.Testing.LocalVerification { } operation TypeArgumentsInference6<'T>(cnt: Int, arg : 'T) : Unit { - mutable arr = new ('T => Unit)[0]; + mutable arr = []; set arr = [TypeArgumentsInference6(1, _)]; arr[0](arg); } operation TypeArgumentsInference7<'T>(cnt: Int, arg : 'T) : Unit { - mutable arr = new ('T => Unit)[0]; + mutable arr = []; set arr += [TypeArgumentsInference7(1, _)]; arr[0](arg); } @@ -69,7 +69,7 @@ namespace Microsoft.Quantum.Testing.LocalVerification { } operation TypeArgumentsInference10<'T>(cnt: Int, arg : 'T) : Unit { - mutable arr = new (Int => Unit)[0]; + mutable arr = []; set arr += [TypeArgumentsInference12(_, arg), TypeArgumentsInference12(_, "")]; arr[0](cnt - 1); } @@ -94,14 +94,14 @@ namespace Microsoft.Quantum.Testing.LocalVerification { } operation TypeArgumentsInference14<'T>(cnt: Int, arg : 'T) : Unit { - mutable arr = new (Int => Unit)[0]; + mutable arr = []; set arr = [TypeArgumentsInference14(_, PauliX)]; set arr = [TypeArgumentsInference14(_, arg)]; arr[0](cnt - 1); } operation TypeArgumentsInference15<'T>(cnt: Int, arg : 'T) : Unit { - mutable arr = new (Int => Unit)[0]; + mutable arr = []; set arr += [TypeArgumentsInference15(_, PauliX)]; set arr += [TypeArgumentsInference15(_, arg)]; arr[1](cnt - 1); @@ -300,7 +300,7 @@ namespace Microsoft.Quantum.Testing.LocalVerification { } operation VariableDeclaration13<'T>(cnt: Int, arg : 'T) : Unit { - mutable arr = new ((Int, 'T) => Unit)[0]; + mutable arr = []; set arr += [VariableDeclaration12]; arr[0](cnt - 1, arg); } @@ -312,13 +312,13 @@ namespace Microsoft.Quantum.Testing.LocalVerification { } operation VariableDeclaration15<'T>(cnt: Int, arg : 'T) : Unit { - mutable arr = new ((Int, 'T) => Unit)[0]; + mutable arr = []; set arr = [VariableDeclaration15]; arr[0](cnt - 1, arg); } operation VariableDeclaration16<'T>(cnt: Int, arg : 'T) : Unit { - mutable arr = new ((Int, 'T) => Unit)[0]; + mutable arr = []; set arr += [VariableDeclaration16]; arr[0](cnt - 1, arg); } @@ -351,7 +351,7 @@ namespace Microsoft.Quantum.Testing.LocalVerification { let tuple = (1, (VariableDeclaration21, "")); let a1 = [VariableDeclaration21]; mutable a2 = [VariableDeclaration21]; - mutable arr = new ((Int, Double) => Unit)[0]; + mutable arr = []; set arr = [VariableDeclaration21]; set arr += [VariableDeclaration21]; set arr w/= 0 <- VariableDeclaration21; @@ -442,7 +442,7 @@ namespace Microsoft.Quantum.Testing.LocalVerification { } function CopyAndUpdateArray3 (arr : Int[][]) : Int[][] { - return arr w/ 0 <- new Int[10]; + return arr w/ 0 <- [0, size = 10]; } function CopyAndUpdateArray4<'T> (arr : 'T[]) : 'T[] { @@ -527,27 +527,27 @@ namespace Microsoft.Quantum.Testing.LocalVerification { // update-and-reassign array function UpdateAndReassign1 () : Unit { - mutable arr = new Int[10]; + mutable arr = [0, size = 10]; set arr w/= 1 <- 0; } function UpdateAndReassign2 () : Unit { - mutable arr = new Int[10]; + mutable arr = [0, size = 10]; set arr w/= 0 .. 2 <- [0,0,0]; } function UpdateAndReassign3 () : Unit { - mutable arr = new Int[10]; + mutable arr = [0, size = 10]; set arr w/= 0 .. Length(arr)-1 <- arr w/ 0 <- 1; } function UpdateAndReassign4 () : Unit { - mutable arr = new Int[10]; + mutable arr = [0, size = 10]; set arr w/= 1 <- 0.; } function UpdateAndReassign5 () : Unit { - mutable arr = new Int[10]; + mutable arr = [0, size = 10]; set arr w/= 0 .. Length(arr) <- 1 .. Length(arr); } @@ -634,12 +634,12 @@ namespace Microsoft.Quantum.Testing.LocalVerification { } function ApplyAndReassign9 () : Unit { - mutable a = new Int[10]; + mutable a = [0, size = 10]; set a[0] = 1; } function ApplyAndReassign10 () : Unit { - mutable a = new Int[10]; + mutable a = [0, size = 10]; set a[0] += 1; } @@ -691,7 +691,7 @@ namespace Microsoft.Quantum.Testing.LocalVerification { fail "length mismatch"; } - mutable res = new (Int,Int,Int)[0]; + mutable res = []; for (i1, i2) in arg2::Name { set res += [(i1, i2, arg1::Name[Length(res)])]; } @@ -814,8 +814,8 @@ namespace Microsoft.Quantum.Testing.LocalVerification { function ItemUpdate9 () : Unit { mutable arr = new ArrayType10[5]; for i in 0..4 { - mutable item = arr[i] w/ Phase <- new Int[10]; - set item w/= Const <- new Double[10]; + mutable item = arr[i] w/ Phase <- [0, size = 10]; + set item w/= Const <- [0.0, size = 10]; set arr w/= i <- item; } } @@ -823,7 +823,7 @@ namespace Microsoft.Quantum.Testing.LocalVerification { function ItemUpdate10 () : Unit { mutable arr = new ArrayType10[5]; for i in 0..4 { - mutable item = arr[i] w/ Phase <- new Int[10]; + mutable item = arr[i] w/ Phase <- [0, size = 10]; set item::Phase w/= 0 <- 1; } } @@ -831,7 +831,7 @@ namespace Microsoft.Quantum.Testing.LocalVerification { function ItemUpdate11 () : Unit { mutable arr = new ArrayType10[5]; for i in 0..4 { - set arr[i] w/= Phase <- new Int[10]; + set arr[i] w/= Phase <- [0, size = 10]; } } diff --git a/src/QsCompiler/Tests.Compiler/TypeCheckingTests.fs b/src/QsCompiler/Tests.Compiler/TypeCheckingTests.fs index 742fc83817..b4433e13dc 100644 --- a/src/QsCompiler/Tests.Compiler/TypeCheckingTests.fs +++ b/src/QsCompiler/Tests.Compiler/TypeCheckingTests.fs @@ -91,12 +91,12 @@ type TypeCheckingTests() = [] member this.Variance() = - this.Expect "Variance1" [] - this.Expect "Variance2" [ Error ErrorCode.TypeMismatch ] - this.Expect "Variance3" [ Error ErrorCode.TypeMismatch ] - this.Expect "Variance4" [ Error ErrorCode.TypeMismatch ] - this.Expect "Variance5" [ Error ErrorCode.TypeMismatch ] - this.Expect "Variance6" [ Error ErrorCode.TypeMismatch ] + this.Expect "Variance1" (Warning WarningCode.DeprecatedNewArray |> List.replicate 5) + this.Expect "Variance2" [ Error ErrorCode.TypeMismatch; Warning WarningCode.DeprecatedNewArray ] + this.Expect "Variance3" [ Error ErrorCode.TypeMismatch; Warning WarningCode.DeprecatedNewArray ] + this.Expect "Variance4" [ Error ErrorCode.TypeMismatch; Warning WarningCode.DeprecatedNewArray ] + this.Expect "Variance5" [ Error ErrorCode.TypeMismatch; Warning WarningCode.DeprecatedNewArray ] + this.Expect "Variance6" [ Error ErrorCode.TypeMismatch; Warning WarningCode.DeprecatedNewArray ] this.Expect "Variance7" @@ -137,10 +137,32 @@ type TypeCheckingTests() = [] member this.``Common base type``() = - this.Expect "CommonBaseType1" [] - this.Expect "CommonBaseType2" [ Error ErrorCode.TypeIntersectionMismatch ] - this.Expect "CommonBaseType3" [ Error ErrorCode.TypeIntersectionMismatch ] - this.Expect "CommonBaseType4" [ Error ErrorCode.TypeMismatchInReturn ] + this.Expect "CommonBaseType1" (Warning WarningCode.DeprecatedNewArray |> List.replicate 2) + + this.Expect + "CommonBaseType2" + [ + Error ErrorCode.TypeIntersectionMismatch + Warning WarningCode.DeprecatedNewArray + Warning WarningCode.DeprecatedNewArray + ] + + this.Expect + "CommonBaseType3" + [ + Error ErrorCode.TypeIntersectionMismatch + Warning WarningCode.DeprecatedNewArray + Warning WarningCode.DeprecatedNewArray + ] + + this.Expect + "CommonBaseType4" + [ + Error ErrorCode.TypeMismatchInReturn + Warning WarningCode.DeprecatedNewArray + Warning WarningCode.DeprecatedNewArray + ] + this.Expect "CommonBaseType5" [] this.Expect "CommonBaseType6" [] this.Expect "CommonBaseType7" [] @@ -155,9 +177,30 @@ type TypeCheckingTests() = this.Expect "CommonBaseType16" [ Error ErrorCode.TypeIntersectionMismatch ] this.Expect "CommonBaseType17" [] this.Expect "CommonBaseType18" [] - this.Expect "CommonBaseType19" [ Warning WarningCode.UnusedTypeParam ] - this.Expect "CommonBaseType20" [ Error ErrorCode.TypeIntersectionMismatch ] - this.Expect "CommonBaseType21" [] + + this.Expect + "CommonBaseType19" + [ + Warning WarningCode.UnusedTypeParam + Warning WarningCode.DeprecatedNewArray + Warning WarningCode.DeprecatedNewArray + ] + + this.Expect + "CommonBaseType20" + [ + Error ErrorCode.TypeIntersectionMismatch + Warning WarningCode.DeprecatedNewArray + Warning WarningCode.DeprecatedNewArray + ] + + this.Expect + "CommonBaseType21" + [ + Warning WarningCode.DeprecatedNewArray + Warning WarningCode.DeprecatedNewArray + ] + this.Expect "CommonBaseType22" [] this.Expect "CommonBaseType23" [] this.Expect "CommonBaseType24" [] @@ -221,7 +264,7 @@ type TypeCheckingTests() = member this.``Argument matching``() = this.Expect "MatchArgument1" [] this.Expect "MatchArgument2" [] - this.Expect "MatchArgument3" [] + this.Expect "MatchArgument3" (Warning WarningCode.DeprecatedNewArray |> List.replicate 2) this.Expect "MatchArgument4" [] this.Expect "MatchArgument5" [] this.Expect "MatchArgument6" [] diff --git a/src/QsCompiler/TextProcessor/QsExpressionParsing.fs b/src/QsCompiler/TextProcessor/QsExpressionParsing.fs index b9c0eace8e..b5f1157736 100644 --- a/src/QsCompiler/TextProcessor/QsExpressionParsing.fs +++ b/src/QsCompiler/TextProcessor/QsExpressionParsing.fs @@ -515,19 +515,28 @@ let private valueArray = <|> bracketDefinedCommaSepExpr (lArray, rArray) /// Parses a Q# array declaration as QsExpression. -/// Raises an InvalidContructorExpression if the array declaration keyword is not followed by a valid array constructor, +/// Adds an InvalidConstructorExpression if the array declaration keyword is not followed by a valid array constructor, /// and advances to the next whitespace character or QsFragmentHeader. let private newArray = let itemType = expectedQsType (lArray >>% ()) >>= fun itemType -> validateTypeSyntax true itemType >>% itemType let body = itemType .>>. (arrayBrackets (expectedExpr eof) |>> fst) |>> NewArray + let toExpr headRange (kind, bodyRange) = + QsExpression.New(kind, Range.Span headRange bodyRange) + let invalid = checkForInvalid (qsFragmentHeader >>% "" <|> (nextCharSatisfies Text.IsWhitespace >>. emptySpace)) ErrorCode.InvalidConstructorExpression >>% unknownExpr - arrayDecl.parse >>. (term body |>> QsExpression.New <|> (term invalid |>> fst)) + let withWarning (expr: QsExpression) = + let range = expr.Range |> QsNullable.defaultValue Range.Zero + QsCompilerDiagnostic.Warning(WarningCode.DeprecatedNewArray, []) range |> pushDiagnostic >>% expr + + arrayDecl.parse + >>= fun headRange -> term body |>> toExpr headRange <|> (term invalid |>> fst) + >>= withWarning /// used to temporarily store item accessors for both array item and named item access expressions type private ItemAccessor =