diff --git a/src/QsCompiler/CompilationManager/ProjectManager.cs b/src/QsCompiler/CompilationManager/ProjectManager.cs index 24defec15f..714e55c7d1 100644 --- a/src/QsCompiler/CompilationManager/ProjectManager.cs +++ b/src/QsCompiler/CompilationManager/ProjectManager.cs @@ -372,7 +372,7 @@ private void ReloadProjectReference(IDictionary projectOutputPaths, U (code, args) => diagnostics.Add(Errors.LoadError(code, args, MessageSource(this.ProjectFile)))); this.projectReferenceDiagnostics = this.projectReferenceDiagnostics.RemoveAll(d => - (d.Source == MessageSource(projectReference) && d.Code != WarningCode.DuplicateProjectReference.Code()) + (d.Source == MessageSource(projectReference) && d.IsWarning() && d.Code != WarningCode.DuplicateProjectReference.Code()) || DiagnosticTools.ErrorType(ErrorCode.ConflictInReferences)(d)) .Concat(diagnostics).ToImmutableArray(); this.Manager.PublishDiagnostics(this.CurrentLoadDiagnostics()); @@ -433,7 +433,7 @@ private void ReloadReferencedAssembly(Uri reference) (code, args) => diagnostics.Add(Errors.LoadError(code, args, MessageSource(this.ProjectFile)))); this.referenceDiagnostics = this.referenceDiagnostics.RemoveAll(d => - (d.Source == MessageSource(reference) && d.Code != WarningCode.DuplicateBinaryFile.Code()) + (d.Source == MessageSource(reference) && d.IsWarning() && d.Code != WarningCode.DuplicateBinaryFile.Code()) || DiagnosticTools.ErrorType(ErrorCode.ConflictInReferences)(d)) .Concat(diagnostics).ToImmutableArray(); this.Manager.PublishDiagnostics(this.CurrentLoadDiagnostics()); @@ -559,7 +559,7 @@ public Task ReloadSourceFileAsync(Uri sourceFile, Func this.loadedSourceFiles = this.loadedSourceFiles.Remove(sourceFile).Concat(loaded.Keys).ToImmutableHashSet(); this.sourceFileDiagnostics = this.sourceFileDiagnostics - .RemoveAll(d => d.Source == MessageSource(sourceFile) && d.Code != WarningCode.DuplicateSourceFile.Code()) + .RemoveAll(d => d.Source == MessageSource(sourceFile) && d.IsWarning() && d.Code != WarningCode.DuplicateSourceFile.Code()) .Concat(diagnostics).ToImmutableArray(); this.Manager.PublishDiagnostics(this.CurrentLoadDiagnostics()); diff --git a/src/QsCompiler/Core/DeclarationHeaders.fs b/src/QsCompiler/Core/DeclarationHeaders.fs index 009c61846f..031a9b6aaf 100644 --- a/src/QsCompiler/Core/DeclarationHeaders.fs +++ b/src/QsCompiler/Core/DeclarationHeaders.fs @@ -45,8 +45,10 @@ module DeclarationHeader = inherit JsonConverter() override this.ReadJson(reader : JsonReader, objectType : Type, existingValue : Offset, hasExistingValue : bool, serializer : JsonSerializer) = - let offset = serializer.Deserialize(reader) - if Object.ReferenceEquals(offset, null) then Offset.Undefined else Offset.Defined offset + if reader.ValueType <> typeof || (string)reader.Value <> "Undefined" then + let offset = serializer.Deserialize(reader) + if Object.ReferenceEquals(offset, null) then Offset.Undefined else Offset.Defined offset + else Offset.Undefined override this.WriteJson(writer : JsonWriter, value : Offset, serializer : JsonSerializer) = match value with @@ -57,8 +59,10 @@ module DeclarationHeader = inherit JsonConverter() override this.ReadJson(reader : JsonReader, objectType : Type, existingValue : Range, hasExistingValue : bool, serializer : JsonSerializer) = - let range = serializer.Deserialize(reader) - if Object.ReferenceEquals(range, null) then Range.Undefined else Range.Defined range + if reader.ValueType <> typeof || (string)reader.Value <> "Undefined" then + let range = serializer.Deserialize(reader) + if Object.ReferenceEquals(range, null) then Range.Undefined else Range.Defined range + else Range.Undefined override this.WriteJson(writer : JsonWriter, value : Range, serializer : JsonSerializer) = match value with diff --git a/src/QsCompiler/Core/SymbolTable.fs b/src/QsCompiler/Core/SymbolTable.fs index d95422441d..126177e02a 100644 --- a/src/QsCompiler/Core/SymbolTable.fs +++ b/src/QsCompiler/Core/SymbolTable.fs @@ -984,7 +984,7 @@ and NamespaceManager // check that there is no more than one entry point, and no entry point if the project is not executable if signatureErrs.Any() then false, errs elif not isExecutable then - errs.Add (offset, range |> orDefault |> QsCompilerDiagnostic.Error (ErrorCode.EntryPointInLibrary, [])) + errs.Add (offset, range |> orDefault |> QsCompilerDiagnostic.Warning (WarningCode.EntryPointInLibrary, [])) false, errs else GetEntryPoints() |> Seq.tryHead |> function | None -> isExecutable, errs diff --git a/src/QsCompiler/DataStructures/Diagnostics.fs b/src/QsCompiler/DataStructures/Diagnostics.fs index 3d67a7db72..04b3a92220 100644 --- a/src/QsCompiler/DataStructures/Diagnostics.fs +++ b/src/QsCompiler/DataStructures/Diagnostics.fs @@ -247,7 +247,8 @@ type ErrorCode = | MissingEntryPoint = 6238 | InvalidEntryPointSpecialization = 6239 | DuplicateEntryPointArgumentName = 6240 - | EntryPointInLibrary = 6241 + | [] + EntryPointInLibrary = 6241 | InvalidTestAttributePlacement = 6242 | InvalidExecutionTargetForTest = 6243 | ExpectingFullNameAsAttributeArgument = 6244 @@ -327,7 +328,8 @@ type WarningCode = | DeprecatedANDoperator = 3302 | DeprecatedORoperator = 3303 | UseOfFutureReservedKeyword = 3304 - | UseOfUnderscorePattern = 3305 + | [] + UseOfUnderscorePattern = 3305 | DeprecatedRUSloopInFunction = 4001 | DiscardingItemInAssignment = 5001 @@ -344,6 +346,7 @@ type WarningCode = | IgnoredEntryPoint = 6203 | ReservedEntryPointArgumentName = 6204 | NonResultTypeReturnedInEntryPoint = 6205 + | EntryPointInLibrary = 6206 | GeneratorDirectiveWillBeIgnored = 6301 | UnreachableCode = 6302 @@ -743,6 +746,7 @@ type DiagnosticItem = | WarningCode.IgnoredEntryPoint -> "Entry point will be ignored. The project is a Q# library and cannot have any entry points." | WarningCode.ReservedEntryPointArgumentName -> "The argument name conflicts with a default argument for a Q# command line application." | WarningCode.NonResultTypeReturnedInEntryPoint -> "Only values of type Result, Result[], and tuples thereof can be returned when executing on a quantum processor." + | WarningCode.EntryPointInLibrary -> "Invalid entry point. Only executable Q# projects can have entry points. Entry point will be ignored. " | WarningCode.GeneratorDirectiveWillBeIgnored -> "Generation directive ignored. A specialization of this callable has been declared as intrinsic." | WarningCode.UnreachableCode -> "This statement will never be executed." diff --git a/src/QsCompiler/DataStructures/Documentation.fs b/src/QsCompiler/DataStructures/Documentation.fs index 6c307fa506..00182bf182 100644 --- a/src/QsCompiler/DataStructures/Documentation.fs +++ b/src/QsCompiler/DataStructures/Documentation.fs @@ -44,7 +44,7 @@ type QsType with | QsTypeKind.Bool -> [ "# Summary" - "Represents a Boolean (true or false) value" + "Represents a Boolean (true or false) value." ] | QsTypeKind.String -> [ @@ -88,7 +88,7 @@ type QsType with [ "# Summary" "Represents a deterministic callable" - "that takes exacly one input argument of the type specified to the left of the arrow" + "that takes exactly one input argument of the type specified to the left of the arrow." "and returns one output value of the type specified to the right of the arrow." "The side effects and output value of a function are always fully defined by its input argument." ] @@ -110,9 +110,7 @@ type QsType with | QsTypeKind.UserDefinedType _ -> [ "# Summary" - "Represents a user defined type." - "User defined types consist of type name and a single item containing an object of their underlying type." - "The contained item can be accessed by applying the postfix unwrap operator \"!\"." + "Represents a user defined type. User defined types consist of named and anonymous items of different types." ] | QsTypeKind.TypeParameter _ -> [ diff --git a/src/QsCompiler/DataStructures/ReservedKeywords.fs b/src/QsCompiler/DataStructures/ReservedKeywords.fs index 492bf9c595..52e0de9a02 100644 --- a/src/QsCompiler/DataStructures/ReservedKeywords.fs +++ b/src/QsCompiler/DataStructures/ReservedKeywords.fs @@ -202,9 +202,6 @@ module InternalUse = "Borrow" "Return" - "Data" // REL0920: can be removed once we give errors for underscore patterns - "Item" // REL0920: can be removed once we give errors for underscore patterns - "QVoid" "Int64" "BigInteger" diff --git a/src/QsCompiler/Tests.Compiler/LinkingTests.fs b/src/QsCompiler/Tests.Compiler/LinkingTests.fs index fdf57e6c47..d189a35046 100644 --- a/src/QsCompiler/Tests.Compiler/LinkingTests.fs +++ b/src/QsCompiler/Tests.Compiler/LinkingTests.fs @@ -285,7 +285,7 @@ type LinkingTests (output:ITestOutputHelper) = for entryPoint in LinkingTests.ReadAndChunkSourceFile "ValidEntryPoints.qs" do this.CompileAndVerify compilationManager entryPoint [] - this.Expect "EntryPointInLibrary" [Error ErrorCode.EntryPointInLibrary] + this.Expect "EntryPointInLibrary" [Warning WarningCode.EntryPointInLibrary] [] diff --git a/src/QsCompiler/Tests.Compiler/SyntaxTests.fs b/src/QsCompiler/Tests.Compiler/SyntaxTests.fs index b5957adbf2..57d6861817 100644 --- a/src/QsCompiler/Tests.Compiler/SyntaxTests.fs +++ b/src/QsCompiler/Tests.Compiler/SyntaxTests.fs @@ -25,48 +25,48 @@ let ``Reserved patterns`` () = ("_mySymbol" , true , Some "_mySymbol" , []) ("mySymbol_" , true , Some "mySymbol_" , []) ("my_symbol" , true , Some "my_symbol" , []) - ("my__symbol", true , Some "my__symbol", [Warning WarningCode.UseOfUnderscorePattern]) - ("__mySymbol", true , Some "__mySymbol", [Warning WarningCode.UseOfUnderscorePattern]) - ("mySymbol__", true , Some "mySymbol__", [Warning WarningCode.UseOfUnderscorePattern]) - ("__my__sym" , true , Some "__my__sym" , [Warning WarningCode.UseOfUnderscorePattern]) - ("my__sym__" , true , Some "my__sym__" , [Warning WarningCode.UseOfUnderscorePattern]) - ("__mysym__" , true , None , [Error ErrorCode.InvalidUseOfReservedKeyword]) + ("my__symbol", true , None , [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("__mySymbol", true , None , [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("mySymbol__", true , None , [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("__my__sym" , true , None , [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("my__sym__" , true , None , [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("__mysym__" , true , None , [Error ErrorCode.InvalidUseOfUnderscorePattern]) ] |> List.iter (testOne (symbolNameLike ErrorCode.InvalidIdentifierName)) [ ("a.b" , true , ([Some "a" ], Some "b" ), []) ("_a.b" , true , ([Some "_a" ], Some "b" ), []) - ("a_.b" , true , ([Some "a_" ], Some "b" ), [Warning WarningCode.UseOfUnderscorePattern]) + ("a_.b" , true , ([None ], Some "b" ), [Error ErrorCode.InvalidUseOfUnderscorePattern]) ("a._b" , true , ([Some "a" ], Some "_b" ), []) ("a.b_" , true , ([Some "a" ], Some "b_" ), []) ("_a.b_" , true , ([Some "_a" ], Some "b_" ), []) - ("a_._b" , true , ([Some "a_" ], Some "_b" ), [Warning WarningCode.UseOfUnderscorePattern]) - ("__a.b" , true , ([Some "__a" ], Some "b" ), [Warning WarningCode.UseOfUnderscorePattern]) - ("a__a.b" , true , ([Some "a__a"], Some "b" ), [Warning WarningCode.UseOfUnderscorePattern]) - ("a__.b" , true , ([Some "a__" ], Some "b" ), [Warning WarningCode.UseOfUnderscorePattern]) - ("a.__b" , true , ([Some "a" ], Some "__b" ), [Warning WarningCode.UseOfUnderscorePattern]) - ("a.b__b" , true , ([Some "a" ], Some "b__b"), [Warning WarningCode.UseOfUnderscorePattern]) - ("a.b__" , true , ([Some "a" ], Some "b__" ), [Warning WarningCode.UseOfUnderscorePattern]) - ("__a.b__", true , ([Some "__a" ], Some "b__" ), [Warning WarningCode.UseOfUnderscorePattern; Warning WarningCode.UseOfUnderscorePattern]) + ("a_._b" , true , ([None ], Some "_b" ), [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("__a.b" , true , ([None ], Some "b" ), [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("a__a.b" , true , ([None ], Some "b" ), [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("a__.b" , true , ([None ], Some "b" ), [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("a.__b" , true , ([Some "a" ], None ), [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("a.b__b" , true , ([Some "a" ], None ), [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("a.b__" , true , ([Some "a" ], None ), [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("__a.b__", true , ([None ], None ), [Error ErrorCode.InvalidUseOfUnderscorePattern; Error ErrorCode.InvalidUseOfUnderscorePattern]) ] |> List.iter (testOne (multiSegmentSymbol ErrorCode.InvalidIdentifierName |>> fst)) [ ("a.b" , true , Some "a.b" , []) ("_a.b" , true , Some "_a.b" , []) - ("a_.b" , true , Some "a_.b" , [Warning WarningCode.UseOfUnderscorePattern]) + ("a_.b" , true , None , [Error ErrorCode.InvalidUseOfUnderscorePattern]) ("a._b" , true , Some "a._b" , []) - ("a.b_" , true , Some "a.b_" , [Warning WarningCode.UseOfUnderscorePattern]) - ("_a.b_" , true , Some "_a.b_" , [Warning WarningCode.UseOfUnderscorePattern]) - ("a_._b" , true , Some "a_._b" , [Warning WarningCode.UseOfUnderscorePattern]) - ("__a.b" , true , Some "__a.b" , [Warning WarningCode.UseOfUnderscorePattern]) - ("a__a.b" , true , Some "a__a.b" , [Warning WarningCode.UseOfUnderscorePattern]) - ("a__.b" , true , Some "a__.b" , [Warning WarningCode.UseOfUnderscorePattern]) - ("a.__b" , true , Some "a.__b" , [Warning WarningCode.UseOfUnderscorePattern]) - ("a.b__b" , true , Some "a.b__b" , [Warning WarningCode.UseOfUnderscorePattern]) - ("a.b__" , true , Some "a.b__" , [Warning WarningCode.UseOfUnderscorePattern]) - ("__a.b__", true , Some "__a.b__", [Warning WarningCode.UseOfUnderscorePattern; Warning WarningCode.UseOfUnderscorePattern]) + ("a.b_" , true , None , [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("_a.b_" , true , None , [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("a_._b" , true , None , [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("__a.b" , true , None , [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("a__a.b" , true , None , [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("a__.b" , true , None , [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("a.__b" , true , None , [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("a.b__b" , true , None , [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("a.b__" , true , None , [Error ErrorCode.InvalidUseOfUnderscorePattern]) + ("__a.b__", true , None , [Error ErrorCode.InvalidUseOfUnderscorePattern; Error ErrorCode.InvalidUseOfUnderscorePattern]) ] - |> List.iter (testOne (namespaceName |>> fst)) + |> List.iter (testOne (namespaceName |>> fst)) [] @@ -255,6 +255,9 @@ let ``Expression literal tests`` () = ("+0xfl", true, toBigInt "15", []); ("0xffl", true, toBigInt "255", []); ("+0xffl", true, toBigInt "255", []); + ("0o1", true, toInt 1, []); + ("+0o1", true, toInt 1, []); + ("-0o1", true, toExpr (NEG (toInt 1)), []); ("0b1", true, toInt 1, []); ("0b100", true, toInt 4, []); ("+0b100", true, toInt 4, []); @@ -263,6 +266,7 @@ let ``Expression literal tests`` () = ("0o100", true, toInt 64, []); ("+0o100", true, toInt 64, []); ("-0o100", true, toExpr (NEG (toInt 64)), []); + (".1e-1", true, toExpr (DoubleLiteral 0.01), []); (".1", true, toExpr (DoubleLiteral 0.1), []); ("1.0", true, toExpr (DoubleLiteral 1.0), []); ("1.", true, toExpr (DoubleLiteral 1.0), []); diff --git a/src/QsCompiler/Tests.Compiler/TypeCheckingTests.fs b/src/QsCompiler/Tests.Compiler/TypeCheckingTests.fs index 208fdee678..c18439576f 100644 --- a/src/QsCompiler/Tests.Compiler/TypeCheckingTests.fs +++ b/src/QsCompiler/Tests.Compiler/TypeCheckingTests.fs @@ -101,10 +101,10 @@ type TypeCheckingTests () = this.Expect "OperationInequality" [Error ErrorCode.InvalidTypeInEqualityComparison] this.Expect "FunctionEquality" [Error ErrorCode.InvalidTypeInEqualityComparison] this.Expect "FunctionInequality" [Error ErrorCode.InvalidTypeInEqualityComparison] - this.Expect "InvalidTypeEquality" [ Error ErrorCode.InvalidUseOfReservedKeyword - Error ErrorCode.InvalidUseOfReservedKeyword ] - this.Expect "InvalidTypeInequality" [ Error ErrorCode.InvalidUseOfReservedKeyword - Error ErrorCode.InvalidUseOfReservedKeyword ] + this.Expect "InvalidTypeEquality" [ Error ErrorCode.InvalidUseOfUnderscorePattern + Error ErrorCode.InvalidUseOfUnderscorePattern ] + this.Expect "InvalidTypeInequality" [ Error ErrorCode.InvalidUseOfUnderscorePattern + Error ErrorCode.InvalidUseOfUnderscorePattern ] this.Expect "NoCommonBaseEquality" [ Error ErrorCode.ArgumentMismatchInBinaryOp Error ErrorCode.ArgumentMismatchInBinaryOp ] this.Expect "NoCommonBaseInequality" [ Error ErrorCode.ArgumentMismatchInBinaryOp diff --git a/src/QsCompiler/TextProcessor/QsFragmentParsing.fs b/src/QsCompiler/TextProcessor/QsFragmentParsing.fs index 2efb549c70..f43644eab5 100644 --- a/src/QsCompiler/TextProcessor/QsFragmentParsing.fs +++ b/src/QsCompiler/TextProcessor/QsFragmentParsing.fs @@ -68,8 +68,7 @@ let internal namespaceName = // internal for testing purposes let names = path @ [sym] let namespaceStr = names |> List.choose id |> String.concat "." if names |> List.contains None then (None, range) |> preturn - elif sym.Value.EndsWith "_" && not (namespaceStr.Contains "__" || namespaceStr.Contains "_.") then // REL0920: remove the second half and return None for pattern errors - buildWarning (preturn range) WarningCode.UseOfUnderscorePattern >>% (Some namespaceStr, range) + elif sym.Value.EndsWith "_" then buildError (preturn range) ErrorCode.InvalidUseOfUnderscorePattern >>% (None, range) else (Some namespaceStr, range) |> preturn multiSegmentSymbol ErrorCode.InvalidPathSegment >>= asNamespaceName diff --git a/src/QsCompiler/TextProcessor/SyntaxBuilder.fs b/src/QsCompiler/TextProcessor/SyntaxBuilder.fs index 59cea4e90c..0615f38a9a 100644 --- a/src/QsCompiler/TextProcessor/SyntaxBuilder.fs +++ b/src/QsCompiler/TextProcessor/SyntaxBuilder.fs @@ -342,16 +342,13 @@ let internal symbolNameLike errCode = |> identifier |> getRange let whenValid ((name : string, range), isBeforeDot) = - // REL0920: - // The warning for futureReservedUnderscorePattern should be replaced with an error in the future, - // and the first half of isReserved should be removed. - let futureReservedUnderscorePattern = name.Contains "__" || (isBeforeDot && name.EndsWith "_") - let isReserved = name.StartsWith "__" && name.EndsWith "__" || InternalUse.CsKeywords.Contains name - let isCsKeyword = SyntaxFacts.IsKeywordKind (SyntaxFacts.GetKeywordKind name) + let reservedUnderscorePattern = name.Contains "__" || (isBeforeDot && name.EndsWith "_") + let isReserved = InternalUse.CsKeywords.Contains + let isCsKeyword = SyntaxFacts.IsKeywordKind << SyntaxFacts.GetKeywordKind let moreThanUnderscores = name.TrimStart('_').Length <> 0 - if isCsKeyword || isReserved then buildError (preturn range) ErrorCode.InvalidUseOfReservedKeyword >>% None + if reservedUnderscorePattern then buildError (preturn range) ErrorCode.InvalidUseOfUnderscorePattern >>% None elif not moreThanUnderscores then buildError (preturn range) errCode >>% None - elif futureReservedUnderscorePattern then buildWarning (preturn range) WarningCode.UseOfUnderscorePattern >>% Some name + elif isReserved name || isCsKeyword name then buildError (preturn range) ErrorCode.InvalidUseOfReservedKeyword >>% None else preturn name |>> Some let invalid = let invalidName = pchar '\'' |> opt >>. manySatisfy isDigit >>. ident