diff --git a/compiler/qsc/src/packages/tests.rs b/compiler/qsc/src/packages/tests.rs index b34206e8b7..6bfcf44fd8 100644 --- a/compiler/qsc/src/packages/tests.rs +++ b/compiler/qsc/src/packages/tests.rs @@ -191,6 +191,7 @@ fn missing_dependency_doesnt_force_failure() { .assert_debug_eq(&errors); } +#[allow(clippy::too_many_lines)] #[test] fn dependency_error() { let mut program = mock_program(); @@ -210,33 +211,58 @@ fn dependency_error() { ); expect![[r#" - [ - WithSource { - sources: [ - Source { - name: "librarymain", - contents: "broken_syntax", - offset: 0, - }, - ], - error: Frontend( - Error( - Parse( - Error( - ExpectedItem( - Ident, - Span { - lo: 0, - hi: 0, - }, - ), + [ + WithSource { + sources: [ + Source { + name: "librarymain", + contents: "broken_syntax", + offset: 0, + }, + ], + error: Frontend( + Error( + Parse( + Error( + Token( + Eof, + Ident, + Span { + lo: 0, + hi: 13, + }, ), ), ), ), - }, - ] - "#]] + ), + }, + WithSource { + sources: [ + Source { + name: "librarymain", + contents: "broken_syntax", + offset: 0, + }, + ], + error: Frontend( + Error( + Parse( + Error( + ExpectedItem( + Eof, + Span { + lo: 0, + hi: 13, + }, + ), + ), + ), + ), + ), + }, + ] + "#]] .assert_debug_eq(&buildable_program.dependency_errors); // compile the user code diff --git a/compiler/qsc_parse/src/item.rs b/compiler/qsc_parse/src/item.rs index 1ea772b5b9..34d91c8c15 100644 --- a/compiler/qsc_parse/src/item.rs +++ b/compiler/qsc_parse/src/item.rs @@ -151,6 +151,7 @@ pub fn parse_implicit_namespace(source_name: &str, s: &mut ParserContext) -> Res } let lo = s.peek().span.lo; let items = parse_namespace_block_contents(s)?; + recovering_token(s, TokenKind::Eof); if items.is_empty() || s.peek().kind != TokenKind::Eof { return Err(Error(ErrorKind::ExpectedItem(s.peek().kind, s.span(lo)))); } diff --git a/compiler/qsc_parse/src/tests/implicit_namespace.rs b/compiler/qsc_parse/src/tests/implicit_namespace.rs index 643765e535..a0816f9d83 100644 --- a/compiler/qsc_parse/src/tests/implicit_namespace.rs +++ b/compiler/qsc_parse/src/tests/implicit_namespace.rs @@ -232,3 +232,171 @@ fn reject_bad_namespace_name_starts_with_number() { )"#]] .assert_eq(&result); } + +#[test] +fn implicit_namespace_with_incomplete_items() { + let result = format!( + "{:#?}", + crate::namespaces( + " +operation Main() : Unit {} +oper", + Some("code/src/Foo.qs"), + LanguageFeatures::default() + ) + ); + expect![[r#" + ( + [ + Namespace { + id: NodeId( + 4294967295, + ), + span: Span { + lo: 1, + hi: 32, + }, + doc: "", + name: Idents( + [ + Ident { + id: NodeId( + 4294967295, + ), + span: Span { + lo: 1, + hi: 32, + }, + name: "code", + }, + Ident { + id: NodeId( + 4294967295, + ), + span: Span { + lo: 1, + hi: 32, + }, + name: "src", + }, + Ident { + id: NodeId( + 4294967295, + ), + span: Span { + lo: 1, + hi: 32, + }, + name: "Foo", + }, + ], + ), + items: [ + Item { + id: NodeId( + 4294967295, + ), + span: Span { + lo: 0, + hi: 27, + }, + doc: "", + attrs: [], + kind: Callable( + CallableDecl { + id: NodeId( + 4294967295, + ), + span: Span { + lo: 1, + hi: 27, + }, + kind: Operation, + name: Ident { + id: NodeId( + 4294967295, + ), + span: Span { + lo: 11, + hi: 15, + }, + name: "Main", + }, + generics: [], + input: Pat { + id: NodeId( + 4294967295, + ), + span: Span { + lo: 15, + hi: 17, + }, + kind: Tuple( + [], + ), + }, + output: Ty { + id: NodeId( + 4294967295, + ), + span: Span { + lo: 20, + hi: 24, + }, + kind: Path( + Path { + id: NodeId( + 4294967295, + ), + span: Span { + lo: 20, + hi: 24, + }, + segments: None, + name: Ident { + id: NodeId( + 4294967295, + ), + span: Span { + lo: 20, + hi: 24, + }, + name: "Unit", + }, + }, + ), + }, + functors: None, + body: Block( + Block { + id: NodeId( + 4294967295, + ), + span: Span { + lo: 25, + hi: 27, + }, + stmts: [], + }, + ), + }, + ), + }, + ], + }, + ], + [ + Error( + Token( + Eof, + Ident, + Span { + lo: 28, + hi: 32, + }, + ), + ), + ], + )"#]] + .assert_eq(&result); +} diff --git a/language_service/src/state/tests.rs b/language_service/src/state/tests.rs index 70bd041eda..53acec1f36 100644 --- a/language_service/src/state/tests.rs +++ b/language_service/src/state/tests.rs @@ -171,13 +171,29 @@ async fn close_last_doc_in_project() { Error( Parse( Error( - ExpectedItem( + Token( + Eof, ClosedBinOp( Slash, ), Span { lo: 59, - hi: 59, + hi: 60, + }, + ), + ), + ), + ), + ), + Frontend( + Error( + Parse( + Error( + ExpectedItem( + Eof, + Span { + lo: 59, + hi: 140, }, ), ), @@ -296,11 +312,27 @@ async fn compile_error() { Error( Parse( Error( - ExpectedItem( + Token( + Eof, Ident, Span { lo: 0, - hi: 0, + hi: 9, + }, + ), + ), + ), + ), + ), + Frontend( + Error( + Parse( + Error( + ExpectedItem( + Eof, + Span { + lo: 0, + hi: 9, }, ), ), @@ -1362,13 +1394,29 @@ async fn close_doc_prioritizes_fs() { Error( Parse( Error( - ExpectedItem( + Token( + Eof, ClosedBinOp( Slash, ), Span { lo: 59, - hi: 59, + hi: 60, + }, + ), + ), + ), + ), + ), + Frontend( + Error( + Parse( + Error( + ExpectedItem( + Eof, + Span { + lo: 59, + hi: 140, }, ), ), @@ -2120,11 +2168,27 @@ async fn error_from_dependency_reported() { Error( Parse( Error( - ExpectedItem( + Token( + Eof, Ident, Span { lo: 0, - hi: 0, + hi: 13, + }, + ), + ), + ), + ), + ), + Frontend( + Error( + Parse( + Error( + ExpectedItem( + Eof, + Span { + lo: 0, + hi: 13, }, ), ), diff --git a/library/qs_source/core/core.qs b/library/core/core.qs similarity index 100% rename from library/qs_source/core/core.qs rename to library/core/core.qs diff --git a/library/qs_source/core/qir.qs b/library/core/qir.qs similarity index 100% rename from library/qs_source/core/qir.qs rename to library/core/qir.qs diff --git a/library/qs_source/qsharp.json b/library/qs_source/qsharp.json deleted file mode 100644 index 0967ef424b..0000000000 --- a/library/qs_source/qsharp.json +++ /dev/null @@ -1 +0,0 @@ -{} diff --git a/library/src/README.md b/library/src/README.md new file mode 100644 index 0000000000..507f4a94ea --- /dev/null +++ b/library/src/README.md @@ -0,0 +1,3 @@ +# Library Rust Crate + +This crate is used for packaging and testing our Q# projects in a Rust environment. \ No newline at end of file diff --git a/library/src/lib.rs b/library/src/lib.rs index de58fef9ea..bef834659a 100644 --- a/library/src/lib.rs +++ b/library/src/lib.rs @@ -12,85 +12,85 @@ pub const QSHARP_LIBRARY_URI_SCHEME: &str = "qsharp-library-source"; pub const CORE_LIB: &[(&str, &str)] = &[ ( "qsharp-library-source:core/core.qs", - include_str!("../qs_source/core/core.qs"), + include_str!("../core/core.qs"), ), ( "qsharp-library-source:core/qir.qs", - include_str!("../qs_source/core/qir.qs"), + include_str!("../core/qir.qs"), ), ]; pub const STD_LIB: &[(&str, &str)] = &[ ( "qsharp-library-source:arrays.qs", - include_str!("../qs_source/src/std/arrays.qs"), + include_str!("../std/src/arrays.qs"), ), ( "qsharp-library-source:canon.qs", - include_str!("../qs_source/src/std/canon.qs"), + include_str!("../std/src/canon.qs"), ), ( "qsharp-library-source:convert.qs", - include_str!("../qs_source/src/std/convert.qs"), + include_str!("../std/src/convert.qs"), ), ( "qsharp-library-source:core.qs", - include_str!("../qs_source/src/std/core.qs"), + include_str!("../std/src/core.qs"), ), ( "qsharp-library-source:diagnostics.qs", - include_str!("../qs_source/src/std/diagnostics.qs"), + include_str!("../std/src/diagnostics.qs"), ), ( "qsharp-library-source:internal.qs", - include_str!("../qs_source/src/std/internal.qs"), + include_str!("../std/src/internal.qs"), ), ( "qsharp-library-source:intrinsic.qs", - include_str!("../qs_source/src/std/intrinsic.qs"), + include_str!("../std/src/intrinsic.qs"), ), ( "qsharp-library-source:logical.qs", - include_str!("../qs_source/src/std/logical.qs"), + include_str!("../std/src/logical.qs"), ), ( "qsharp-library-source:math.qs", - include_str!("../qs_source/src/std/math.qs"), + include_str!("../std/src/math.qs"), ), ( "qsharp-library-source:measurement.qs", - include_str!("../qs_source/src/std/measurement.qs"), + include_str!("../std/src/measurement.qs"), ), ( "qsharp-library-source:qir.qs", - include_str!("../qs_source/src/std/qir.qs"), + include_str!("../std/src/qir.qs"), ), ( "qsharp-library-source:random.qs", - include_str!("../qs_source/src/std/random.qs"), + include_str!("../std/src/random.qs"), ), ( "qsharp-library-source:re.qs", - include_str!("../qs_source/src/std/re.qs"), + include_str!("../std/src/re.qs"), ), ( "qsharp-library-source:unstable_arithmetic.qs", - include_str!("../qs_source/src/std/unstable_arithmetic.qs"), + include_str!("../std/src/unstable_arithmetic.qs"), ), ( "qsharp-library-source:unstable_arithmetic_internal.qs", - include_str!("../qs_source/src/std/unstable_arithmetic_internal.qs"), + include_str!("../std/src/unstable_arithmetic_internal.qs"), ), ( "qsharp-library-source:unstable_state_preparation.qs", - include_str!("../qs_source/src/std/unstable_state_preparation.qs"), + include_str!("../std/src/unstable_state_preparation.qs"), ), ( "qsharp-library-source:unstable_table_lookup.qs", - include_str!("../qs_source/src/std/unstable_table_lookup.qs"), + include_str!("../std/src/unstable_table_lookup.qs"), ), ( "qsharp-library-source:modern_api.qs", - include_str!("../qs_source/src/std/modern_api.qs"), + include_str!("../std/src/modern_api.qs"), ), ]; diff --git a/library/README.md b/library/std/README.md similarity index 100% rename from library/README.md rename to library/std/README.md diff --git a/library/std/qsharp.json b/library/std/qsharp.json new file mode 100644 index 0000000000..ed9a1ca5e3 --- /dev/null +++ b/library/std/qsharp.json @@ -0,0 +1,24 @@ +{ + "author": "Microsoft", + "license": "MIT", + "files": [ + "src/std/arrays.qs", + "src/std/canon.qs", + "src/std/convert.qs", + "src/std/core.qs", + "src/std/diagnostics.qs", + "src/std/internal.qs", + "src/std/intrinsic.qs", + "src/std/logical.qs", + "src/std/math.qs", + "src/std/measurement.qs", + "src/std/modern_api.qs", + "src/std/qir.qs", + "src/std/random.qs", + "src/std/re.qs", + "src/std/unstable_arithmetic.qs", + "src/std/unstable_arithmetic_internal.qs", + "src/std/unstable_state_preparation.qs", + "src/std/unstable_table_lookup.qs" + ] +} \ No newline at end of file diff --git a/library/qs_source/src/std/arrays.qs b/library/std/src/arrays.qs similarity index 100% rename from library/qs_source/src/std/arrays.qs rename to library/std/src/arrays.qs diff --git a/library/qs_source/src/std/canon.qs b/library/std/src/canon.qs similarity index 100% rename from library/qs_source/src/std/canon.qs rename to library/std/src/canon.qs diff --git a/library/qs_source/src/std/convert.qs b/library/std/src/convert.qs similarity index 100% rename from library/qs_source/src/std/convert.qs rename to library/std/src/convert.qs diff --git a/library/qs_source/src/std/core.qs b/library/std/src/core.qs similarity index 100% rename from library/qs_source/src/std/core.qs rename to library/std/src/core.qs diff --git a/library/qs_source/src/std/diagnostics.qs b/library/std/src/diagnostics.qs similarity index 100% rename from library/qs_source/src/std/diagnostics.qs rename to library/std/src/diagnostics.qs diff --git a/library/qs_source/src/std/internal.qs b/library/std/src/internal.qs similarity index 100% rename from library/qs_source/src/std/internal.qs rename to library/std/src/internal.qs diff --git a/library/qs_source/src/std/intrinsic.qs b/library/std/src/intrinsic.qs similarity index 100% rename from library/qs_source/src/std/intrinsic.qs rename to library/std/src/intrinsic.qs diff --git a/library/qs_source/src/std/logical.qs b/library/std/src/logical.qs similarity index 100% rename from library/qs_source/src/std/logical.qs rename to library/std/src/logical.qs diff --git a/library/qs_source/src/std/math.qs b/library/std/src/math.qs similarity index 100% rename from library/qs_source/src/std/math.qs rename to library/std/src/math.qs diff --git a/library/qs_source/src/std/measurement.qs b/library/std/src/measurement.qs similarity index 100% rename from library/qs_source/src/std/measurement.qs rename to library/std/src/measurement.qs diff --git a/library/qs_source/src/std/modern_api.qs b/library/std/src/modern_api.qs similarity index 100% rename from library/qs_source/src/std/modern_api.qs rename to library/std/src/modern_api.qs diff --git a/library/qs_source/src/std/qir.qs b/library/std/src/qir.qs similarity index 100% rename from library/qs_source/src/std/qir.qs rename to library/std/src/qir.qs diff --git a/library/qs_source/src/std/random.qs b/library/std/src/random.qs similarity index 100% rename from library/qs_source/src/std/random.qs rename to library/std/src/random.qs diff --git a/library/qs_source/src/std/re.qs b/library/std/src/re.qs similarity index 100% rename from library/qs_source/src/std/re.qs rename to library/std/src/re.qs diff --git a/library/qs_source/src/std/unstable_arithmetic.qs b/library/std/src/unstable_arithmetic.qs similarity index 100% rename from library/qs_source/src/std/unstable_arithmetic.qs rename to library/std/src/unstable_arithmetic.qs diff --git a/library/qs_source/src/std/unstable_arithmetic_internal.qs b/library/std/src/unstable_arithmetic_internal.qs similarity index 100% rename from library/qs_source/src/std/unstable_arithmetic_internal.qs rename to library/std/src/unstable_arithmetic_internal.qs diff --git a/library/qs_source/src/std/unstable_state_preparation.qs b/library/std/src/unstable_state_preparation.qs similarity index 100% rename from library/qs_source/src/std/unstable_state_preparation.qs rename to library/std/src/unstable_state_preparation.qs diff --git a/library/qs_source/src/std/unstable_table_lookup.qs b/library/std/src/unstable_table_lookup.qs similarity index 100% rename from library/qs_source/src/std/unstable_table_lookup.qs rename to library/std/src/unstable_table_lookup.qs