diff --git a/src/QsCompiler/Core/SymbolTable.fs b/src/QsCompiler/Core/SymbolTable.fs index cb4fc0c521..c77348c849 100644 --- a/src/QsCompiler/Core/SymbolTable.fs +++ b/src/QsCompiler/Core/SymbolTable.fs @@ -941,24 +941,19 @@ and NamespaceManager errs.Add (decl.Position, signature.Characteristics.Range.ValueOr decl.Range |> QsCompilerDiagnostic.Error (ErrorCode.InvalidEntryPointSpecialization, [])) // validate entry point argument and return type - let rec validateArgAndReturnTypes (isArg, inArray) (t : QsType) = - let supportedItemType = function - | Int | Double | Bool | String -> true - | _ -> false - match t.Type with + let validateArgAndReturnTypes isArg (qsType : QsType) = + let rec IsArray = function + | ArrayType _ -> true + | TupleType (ts : ImmutableArray) when ts.Length = 1 -> IsArray ts.[0].Type + | _ -> false + qsType.ExtractAll (fun t -> t.Type |> function // ExtractAll recurs on all subtypes (e.g. callable in- and output types as well) | Qubit -> (decl.Position, t.Range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.QubitTypeInEntryPointSignature, [])) |> Seq.singleton - | UserDefinedType _ -> (decl.Position, t.Range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.UserDefinedTypeInEntryPointSignature, [])) |> Seq.singleton | QsTypeKind.Operation _ -> (decl.Position, t.Range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.CallableTypeInEntryPointSignature, [])) |> Seq.singleton | QsTypeKind.Function _ -> (decl.Position, t.Range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.CallableTypeInEntryPointSignature, [])) |> Seq.singleton + | UserDefinedType _ -> (decl.Position, t.Range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.UserDefinedTypeInEntryPointSignature, [])) |> Seq.singleton | TupleType ts when ts.Length > 1 && isArg -> (decl.Position, t.Range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.InnerTupleInEntryPointArgument, [])) |> Seq.singleton - | TupleType ts -> ts |> Seq.collect (validateArgAndReturnTypes (isArg, inArray)) - | ArrayType _ when isArg && inArray -> (decl.Position, t.Range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.ArrayOfArrayInEntryPointArgument, [])) |> Seq.singleton - | ArrayType bt -> validateArgAndReturnTypes (isArg, true) bt - | _ when isArg && inArray -> - if supportedItemType t.Type then Seq.empty - else (decl.Position, t.Range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.UnsupportedItemTypeInEntryPointArgument, [])) |> Seq.singleton - | _ -> Seq.empty - let validateArgAndReturnTypes isArg = validateArgAndReturnTypes (isArg, false) + | ArrayType bt when isArg && bt.Type |> IsArray -> (decl.Position, t.Range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.ArrayOfArrayInEntryPointArgument, [])) |> Seq.singleton + | _ -> Seq.empty) let inErrs = signature.Argument.Items.Select snd |> Seq.collect (validateArgAndReturnTypes true) let outErrs = signature.ReturnType |> validateArgAndReturnTypes false let signatureErrs = inErrs.Concat outErrs diff --git a/src/QsCompiler/DataStructures/Diagnostics.fs b/src/QsCompiler/DataStructures/Diagnostics.fs index b799fe2cb8..58f961968e 100644 --- a/src/QsCompiler/DataStructures/Diagnostics.fs +++ b/src/QsCompiler/DataStructures/Diagnostics.fs @@ -236,18 +236,17 @@ type ErrorCode = | UserDefinedTypeInEntryPointSignature = 6233 | InnerTupleInEntryPointArgument = 6234 | ArrayOfArrayInEntryPointArgument = 6235 - | UnsupportedItemTypeInEntryPointArgument = 6236 - | OtherEntryPointExists = 6237 - | MultipleEntryPoints = 6238 - | MissingEntryPoint = 6239 - | InvalidEntryPointSpecialization = 6240 - | DuplicateEntryPointArgumentName = 6241 - | EntryPointInLibrary = 6242 - | InvalidTestAttributePlacement = 6243 - | InvalidExecutionTargetForTest = 6244 - | ExpectingFullNameAsAttributeArgument = 6245 - | AttributeInvalidOnSpecialization = 6246 - | AttributeInvalidOnCallable = 6247 + | OtherEntryPointExists = 6236 + | MultipleEntryPoints = 6237 + | MissingEntryPoint = 6238 + | InvalidEntryPointSpecialization = 6239 + | DuplicateEntryPointArgumentName = 6240 + | EntryPointInLibrary = 6241 + | InvalidTestAttributePlacement = 6242 + | InvalidExecutionTargetForTest = 6243 + | ExpectingFullNameAsAttributeArgument = 6244 + | AttributeInvalidOnSpecialization = 6245 + | AttributeInvalidOnCallable = 6246 | TypeMismatchInReturn = 6301 | TypeMismatchInValueUpdate = 6302 @@ -614,7 +613,6 @@ type DiagnosticItem = | ErrorCode.UserDefinedTypeInEntryPointSignature -> "Invalid entry point. Values of user defined type may not be used as arguments or return values to entry points." | ErrorCode.InnerTupleInEntryPointArgument -> "Anonymous tuple items or arrays of tuples are not supported in entry point arguments. All items need to be named." | ErrorCode.ArrayOfArrayInEntryPointArgument -> "Multi-dimensional arrays are not supported in entry point arguments." - | ErrorCode.UnsupportedItemTypeInEntryPointArgument -> "Unsupported item type in entry point argument. Array items may only contain values of type Int, Double, Bool, and String." | ErrorCode.OtherEntryPointExists -> "Invalid entry point. An entry point {0} already exists in {1}." | ErrorCode.MultipleEntryPoints -> "The project contains more than one entry point." | ErrorCode.MissingEntryPoint -> "Missing entry point. Execution on a quantum processor requires that a Q# entry point is defined using the @EntryPoint() attribute. Any C# driver code should be defined in a separate project." diff --git a/src/QsCompiler/Tests.Compiler/LinkingTests.fs b/src/QsCompiler/Tests.Compiler/LinkingTests.fs index b41a794f9c..71a37aa81a 100644 --- a/src/QsCompiler/Tests.Compiler/LinkingTests.fs +++ b/src/QsCompiler/Tests.Compiler/LinkingTests.fs @@ -294,56 +294,52 @@ type LinkingTests (output:ITestOutputHelper) = member this.``Entry point argument and return type verification`` () = this.Expect "InvalidEntryPoint1" [Error ErrorCode.QubitTypeInEntryPointSignature] - this.Expect "InvalidEntryPoint2" [Error ErrorCode.InnerTupleInEntryPointArgument] + this.Expect "InvalidEntryPoint2" [Error ErrorCode.QubitTypeInEntryPointSignature; Error ErrorCode.InnerTupleInEntryPointArgument] this.Expect "InvalidEntryPoint3" [Error ErrorCode.QubitTypeInEntryPointSignature] this.Expect "InvalidEntryPoint4" [Error ErrorCode.QubitTypeInEntryPointSignature] this.Expect "InvalidEntryPoint5" [Error ErrorCode.QubitTypeInEntryPointSignature] this.Expect "InvalidEntryPoint6" [Error ErrorCode.QubitTypeInEntryPointSignature] this.Expect "InvalidEntryPoint7" [Error ErrorCode.CallableTypeInEntryPointSignature] - this.Expect "InvalidEntryPoint8" [Error ErrorCode.InnerTupleInEntryPointArgument] - this.Expect "InvalidEntryPoint9" [Error ErrorCode.InnerTupleInEntryPointArgument] + this.Expect "InvalidEntryPoint8" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.InnerTupleInEntryPointArgument] + this.Expect "InvalidEntryPoint9" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.InnerTupleInEntryPointArgument] this.Expect "InvalidEntryPoint10" [Error ErrorCode.CallableTypeInEntryPointSignature] this.Expect "InvalidEntryPoint11" [Error ErrorCode.CallableTypeInEntryPointSignature] this.Expect "InvalidEntryPoint12" [Error ErrorCode.CallableTypeInEntryPointSignature] - this.Expect "InvalidEntryPoint13" [Error ErrorCode.CallableTypeInEntryPointSignature] - this.Expect "InvalidEntryPoint14" [Error ErrorCode.CallableTypeInEntryPointSignature] - this.Expect "InvalidEntryPoint15" [Error ErrorCode.CallableTypeInEntryPointSignature] - this.Expect "InvalidEntryPoint16" [Error ErrorCode.CallableTypeInEntryPointSignature] + this.Expect "InvalidEntryPoint13" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.QubitTypeInEntryPointSignature] + this.Expect "InvalidEntryPoint14" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.QubitTypeInEntryPointSignature] + this.Expect "InvalidEntryPoint15" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.QubitTypeInEntryPointSignature] + this.Expect "InvalidEntryPoint16" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.QubitTypeInEntryPointSignature] this.Expect "InvalidEntryPoint17" [Error ErrorCode.CallableTypeInEntryPointSignature] - this.Expect "InvalidEntryPoint18" [Error ErrorCode.InnerTupleInEntryPointArgument] - this.Expect "InvalidEntryPoint19" [Error ErrorCode.InnerTupleInEntryPointArgument] + this.Expect "InvalidEntryPoint18" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.InnerTupleInEntryPointArgument] + this.Expect "InvalidEntryPoint19" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.InnerTupleInEntryPointArgument] this.Expect "InvalidEntryPoint20" [Error ErrorCode.CallableTypeInEntryPointSignature] this.Expect "InvalidEntryPoint21" [Error ErrorCode.CallableTypeInEntryPointSignature] this.Expect "InvalidEntryPoint22" [Error ErrorCode.CallableTypeInEntryPointSignature] - this.Expect "InvalidEntryPoint23" [Error ErrorCode.CallableTypeInEntryPointSignature] - this.Expect "InvalidEntryPoint24" [Error ErrorCode.CallableTypeInEntryPointSignature] - this.Expect "InvalidEntryPoint25" [Error ErrorCode.CallableTypeInEntryPointSignature] - this.Expect "InvalidEntryPoint26" [Error ErrorCode.CallableTypeInEntryPointSignature] + this.Expect "InvalidEntryPoint23" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.QubitTypeInEntryPointSignature] + this.Expect "InvalidEntryPoint24" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.QubitTypeInEntryPointSignature] + this.Expect "InvalidEntryPoint25" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.QubitTypeInEntryPointSignature] + this.Expect "InvalidEntryPoint26" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.QubitTypeInEntryPointSignature] this.Expect "InvalidEntryPoint27" [Error ErrorCode.UserDefinedTypeInEntryPointSignature] - this.Expect "InvalidEntryPoint28" [Error ErrorCode.InnerTupleInEntryPointArgument] + this.Expect "InvalidEntryPoint28" [Error ErrorCode.UserDefinedTypeInEntryPointSignature; Error ErrorCode.InnerTupleInEntryPointArgument] this.Expect "InvalidEntryPoint29" [Error ErrorCode.UserDefinedTypeInEntryPointSignature] this.Expect "InvalidEntryPoint30" [Error ErrorCode.UserDefinedTypeInEntryPointSignature] this.Expect "InvalidEntryPoint31" [Error ErrorCode.UserDefinedTypeInEntryPointSignature] this.Expect "InvalidEntryPoint32" [Error ErrorCode.UserDefinedTypeInEntryPointSignature] - this.Expect "InvalidEntryPoint33" [Error ErrorCode.CallableTypeInEntryPointSignature] - this.Expect "InvalidEntryPoint34" [Error ErrorCode.CallableTypeInEntryPointSignature] - this.Expect "InvalidEntryPoint35" [Error ErrorCode.CallableTypeInEntryPointSignature] - this.Expect "InvalidEntryPoint36" [Error ErrorCode.CallableTypeInEntryPointSignature] + this.Expect "InvalidEntryPoint33" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.UserDefinedTypeInEntryPointSignature] + this.Expect "InvalidEntryPoint34" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.UserDefinedTypeInEntryPointSignature] + this.Expect "InvalidEntryPoint35" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.UserDefinedTypeInEntryPointSignature] + this.Expect "InvalidEntryPoint36" [Error ErrorCode.CallableTypeInEntryPointSignature; Error ErrorCode.UserDefinedTypeInEntryPointSignature] this.Expect "InvalidEntryPoint37" [Error ErrorCode.InnerTupleInEntryPointArgument] this.Expect "InvalidEntryPoint38" [Error ErrorCode.InnerTupleInEntryPointArgument] this.Expect "InvalidEntryPoint39" [Error ErrorCode.ArrayOfArrayInEntryPointArgument] this.Expect "InvalidEntryPoint40" [Error ErrorCode.ArrayOfArrayInEntryPointArgument] this.Expect "InvalidEntryPoint41" [Error ErrorCode.ArrayOfArrayInEntryPointArgument] - this.Expect "InvalidEntryPoint42" [Error ErrorCode.UnsupportedItemTypeInEntryPointArgument] - this.Expect "InvalidEntryPoint43" [Error ErrorCode.UnsupportedItemTypeInEntryPointArgument] - this.Expect "InvalidEntryPoint44" [Error ErrorCode.UnsupportedItemTypeInEntryPointArgument] - this.Expect "InvalidEntryPoint45" [Error ErrorCode.UnsupportedItemTypeInEntryPointArgument] [] diff --git a/src/QsCompiler/Tests.Compiler/TestCases/LinkingTests/InvalidEntryPoints.qs b/src/QsCompiler/Tests.Compiler/TestCases/LinkingTests/InvalidEntryPoints.qs index ed2156c914..8dfbb83f54 100644 --- a/src/QsCompiler/Tests.Compiler/TestCases/LinkingTests/InvalidEntryPoints.qs +++ b/src/QsCompiler/Tests.Compiler/TestCases/LinkingTests/InvalidEntryPoints.qs @@ -226,7 +226,7 @@ namespace Microsoft.Quantum.Testing.EntryPoints { operation InvalidEntryPoint38(arg1 : (Pauli, Result)[], arg2 : Double) : Unit {} - // array item type validation in entry point arguments + // no arrays of arrays in entry point arguments @ EntryPoint() operation InvalidEntryPoint39(arg : Int[][]) : Unit {} @@ -237,16 +237,4 @@ namespace Microsoft.Quantum.Testing.EntryPoints { @ EntryPoint() operation InvalidEntryPoint41(a : Int[], (b : Int[][], c : Double)) : Unit {} - @ EntryPoint() - operation InvalidEntryPoint42(a : BigInt[]) : Unit {} - - @ EntryPoint() - operation InvalidEntryPoint43(a : Range[]) : Unit {} - - @ EntryPoint() - operation InvalidEntryPoint44(a : Result[]) : Unit {} - - @ EntryPoint() - operation InvalidEntryPoint45(a : Pauli[]) : Unit {} - } diff --git a/src/QsCompiler/Tests.Compiler/TestCases/LinkingTests/ValidEntryPoints.qs b/src/QsCompiler/Tests.Compiler/TestCases/LinkingTests/ValidEntryPoints.qs index 35faf1c04d..56f78c9257 100644 --- a/src/QsCompiler/Tests.Compiler/TestCases/LinkingTests/ValidEntryPoints.qs +++ b/src/QsCompiler/Tests.Compiler/TestCases/LinkingTests/ValidEntryPoints.qs @@ -49,7 +49,7 @@ namespace Microsoft.Quantum.Testing.EntryPoints { namespace Microsoft.Quantum.Testing.EntryPoints { @ EntryPoint() - operation ValidEntryPoint6(a : Int, b: Double[]) : Unit {} + operation ValidEntryPoint6(a : Int, b: BigInt[]) : Unit {} } // ================================= @@ -57,7 +57,7 @@ namespace Microsoft.Quantum.Testing.EntryPoints { namespace Microsoft.Quantum.Testing.EntryPoints { @ EntryPoint() - operation ValidEntryPoint7(arg1 : (Int)[], arg2 : Double) : Unit {} + operation ValidEntryPoint7(arg1 : (Pauli)[], arg2 : Double) : Unit {} } // =================================