Skip to content

Commit

Permalink
Use a copy of standard libraries for LSP tests (#5203)
Browse files Browse the repository at this point in the history
## Description

Use a standalone copy of std and core for LSP tests so that they don't
get disrupted by standard library changes.

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.

Co-authored-by: Joshua Batty <[email protected]>
  • Loading branch information
IGI-111 and JoshuaBatty authored Oct 19, 2023
1 parent 264fb70 commit dfa3fe5
Show file tree
Hide file tree
Showing 106 changed files with 16,922 additions and 46 deletions.
2 changes: 1 addition & 1 deletion sway-lsp/tests/fixtures/benchmark/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ license = "Apache-2.0"
name = "sway_project"

[dependencies]
std = { path = "../../../../sway-lib-std" }
std = { path = "../fixtures-std" }
13 changes: 13 additions & 0 deletions sway-lsp/tests/fixtures/completion/Forc.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[package]]
name = "completion"
source = "member"
dependencies = ["std"]

[[package]]
name = "core"
source = "path+from-root-A8024ACE89756498"

[[package]]
name = "std"
source = "path+from-root-A8024ACE89756498"
dependencies = ["core"]
2 changes: 1 addition & 1 deletion sway-lsp/tests/fixtures/completion/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ license = "Apache-2.0"
name = "completion"

[dependencies]
std = { path = "../../../../sway-lib-std" }
std = { path = "../fixtures-std" }
2 changes: 1 addition & 1 deletion sway-lsp/tests/fixtures/diagnostics/dead_code/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ license = "Apache-2.0"
name = "dead_code"

[dependencies]
std = { path = "../../../../../sway-lib-std" }
std = { path = "../../fixtures-std" }
2 changes: 1 addition & 1 deletion sway-lsp/tests/fixtures/diagnostics/multi_file/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ entry = "main.sw"
implicit-std = false

[dependencies]
std = { path = "../../../../../sway-lib-std" }
std = { path = "../../fixtures-std" }
3 changes: 3 additions & 0 deletions sway-lsp/tests/fixtures/fixtures-core/Forc.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = 'core'
source = 'member'
5 changes: 5 additions & 0 deletions sway-lsp/tests/fixtures/fixtures-core/Forc.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[project]
authors = ["Fuel Labs <[email protected]>"]
entry = "lib.sw"
license = "Apache-2.0"
name = "core"
11 changes: 11 additions & 0 deletions sway-lsp/tests/fixtures/fixtures-core/src/lib.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
library;

pub mod primitives;
pub mod raw_ptr;
pub mod raw_slice;
pub mod r#str;
pub mod ops;
pub mod primitive_conversions;
pub mod never;
pub mod r#storage;
pub mod prelude;
78 changes: 78 additions & 0 deletions sway-lsp/tests/fixtures/fixtures-core/src/never.sw
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
library;

use ::ops::{Eq, Not, Ord};

/// `Never` represents the type of computations which never resolve to any value at all.
///
/// # Additional Information
///
/// `break`, `continue` and `return` expressions also have type `Never`. For example we are allowed to
/// write:
///
/// ```sway
/// let x: Never = {
/// return 123
/// };
/// ```
///
/// Although the `let` is pointless here, it illustrates the meaning of `Never`. Since `x` is never
/// assigned a value (because `return` returns from the entire function), `x` can be given type
/// `Never`. We could also replace `return 123` with a `revert()` or a never-ending `loop` and this code
/// would still be valid.
///
/// A more realistic usage of `Never` is in this code:
///
/// ```sway
/// let num: u32 = match get_a_number() {
/// Some(num) => num,
/// None => break,
/// };
/// ```
///
/// Both match arms must produce values of type [`u32`], but since `break` never produces a value
/// at all we know it can never produce a value which isn't a [`u32`]. This illustrates another
/// behaviour of the `Never` type - expressions with type `Never` will coerce into any other type.
///
/// Note that `Never` type coerces into any other type, another example of this would be:
///
/// ```sway
/// let x: u32 = {
/// return 123
/// };
/// ```
///
/// Regardless of the type of `x`, the return block of type `Never` will always coerce into `x` type.
///
/// # Examples
///
/// ```sway
/// fn foo() {
/// let num: u64 = match Option::None::<u64> {
/// Some(num) => num,
/// None => return,
/// };
/// }
/// ```
pub enum Never {}

impl Not for Never {
fn not(self) -> Self {
match self {
}
}
}

impl Eq for Never {
fn eq(self, _other: Self) -> bool {
self
}
}

impl Ord for Never {
fn gt(self, _other: Self) -> bool {
self
}
fn lt(self, _other: Self) -> bool {
self
}
}
Loading

0 comments on commit dfa3fe5

Please sign in to comment.