Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/QsCompiler/CompilationManager/ProjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ private void ReloadProjectReference(IDictionary<Uri, Uri?> 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());
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -559,7 +559,7 @@ public Task ReloadSourceFileAsync(Uri sourceFile, Func<Uri, FileContentManager?>

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());

Expand Down
12 changes: 8 additions & 4 deletions src/QsCompiler/Core/DeclarationHeaders.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ module DeclarationHeader =
inherit JsonConverter<Offset>()

override this.ReadJson(reader : JsonReader, objectType : Type, existingValue : Offset, hasExistingValue : bool, serializer : JsonSerializer) =
let offset = serializer.Deserialize<Position>(reader)
if Object.ReferenceEquals(offset, null) then Offset.Undefined else Offset.Defined offset
if reader.ValueType <> typeof<String> || (string)reader.Value <> "Undefined" then
let offset = serializer.Deserialize<Position>(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
Expand All @@ -57,8 +59,10 @@ module DeclarationHeader =
inherit JsonConverter<Range>()

override this.ReadJson(reader : JsonReader, objectType : Type, existingValue : Range, hasExistingValue : bool, serializer : JsonSerializer) =
let range = serializer.Deserialize<DataTypes.Range>(reader)
if Object.ReferenceEquals(range, null) then Range.Undefined else Range.Defined range
if reader.ValueType <> typeof<String> || (string)reader.Value <> "Undefined" then
let range = serializer.Deserialize<DataTypes.Range>(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
Expand Down
2 changes: 1 addition & 1 deletion src/QsCompiler/Core/SymbolTable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/QsCompiler/DataStructures/Diagnostics.fs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ type ErrorCode =
| MissingEntryPoint = 6238
| InvalidEntryPointSpecialization = 6239
| DuplicateEntryPointArgumentName = 6240
| EntryPointInLibrary = 6241
| [<Obsolete("This diagnostic is no longer in use. The warning EntryPointInLibrary is given instead.")>]
EntryPointInLibrary = 6241
| InvalidTestAttributePlacement = 6242
| InvalidExecutionTargetForTest = 6243
| ExpectingFullNameAsAttributeArgument = 6244
Expand Down Expand Up @@ -327,7 +328,8 @@ type WarningCode =
| DeprecatedANDoperator = 3302
| DeprecatedORoperator = 3303
| UseOfFutureReservedKeyword = 3304
| UseOfUnderscorePattern = 3305
| [<Obsolete("This diagnostic is no longer in use. The error InvalidUseOfUnderscorePattern is given instead.")>]
UseOfUnderscorePattern = 3305
| DeprecatedRUSloopInFunction = 4001

| DiscardingItemInAssignment = 5001
Expand All @@ -344,6 +346,7 @@ type WarningCode =
| IgnoredEntryPoint = 6203
| ReservedEntryPointArgumentName = 6204
| NonResultTypeReturnedInEntryPoint = 6205
| EntryPointInLibrary = 6206
| GeneratorDirectiveWillBeIgnored = 6301
| UnreachableCode = 6302

Expand Down Expand Up @@ -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."

Expand Down
8 changes: 3 additions & 5 deletions src/QsCompiler/DataStructures/Documentation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
[
Expand Down Expand Up @@ -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."
]
Expand All @@ -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 _ ->
[
Expand Down
3 changes: 0 additions & 3 deletions src/QsCompiler/DataStructures/ReservedKeywords.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/QsCompiler/Tests.Compiler/LinkingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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]


[<Fact>]
Expand Down
58 changes: 31 additions & 27 deletions src/QsCompiler/Tests.Compiler/SyntaxTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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))


[<Fact>]
Expand Down Expand Up @@ -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, []);
Expand All @@ -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), []);
Expand Down
8 changes: 4 additions & 4 deletions src/QsCompiler/Tests.Compiler/TypeCheckingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/QsCompiler/TextProcessor/QsFragmentParsing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading