Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for recursive const definitions and associated consts usages #6545

Merged
merged 2 commits into from
Sep 14, 2024
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
script;
library;

fn main() -> u64 {
const X;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ category = "fail"

# check: $()const X;
# nextln: $()Constant requires expression.

# check: $()1 error.
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ category = "fail"

# check: $()const X;
# nextln: $()Constant requires expression.

# check: $()1 error.
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ category = "fail"
# check: $()Function d is recursive via e and f, which is unsupported at this time.
# check: $()Function e is recursive via f and d, which is unsupported at this time.
# check: $()Function f is recursive via d and e, which is unsupported at this time.

# check: $()6 errors.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "recursive_const_associated"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
name = "recursive_const_associated"
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
library;

struct S {}

// TODO: Uncomment this code, and enable this test and add checks once https://github.com/FuelLabs/sway/issues/6537 is fixed.
impl S {
// const A: u8 = Self::B;
// const B: u8 = Self::A;

// const X: u8 = Self::Y;
// const Y: u8 = Self::Z;
// const Z: u8 = Self::X;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
category = "disabled" # TODO: Enable this test and add checks once https://github.com/FuelLabs/sway/issues/6537 is fixed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "recursive_const_associated_over_associated_function"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
name = "recursive_const_associated_over_associated_function"
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
library;

struct S {}

impl S {
fn assoc() -> u8 {
Self::S_ASSOC
}
}

impl S {
const S_ASSOC: u8 = Self::assoc();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
category = "fail"

#check: $()Self::S_ASSOC
#nextln: $()Could not find symbol "S_ASSOC" in this scope.

#check: $()const S_ASSOC: u8 = Self::assoc();
#nextln: $()No method named "assoc" found for type "S".

#check: $()2 errors.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "recursive_const_associated_over_module_function"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
name = "recursive_const_associated_over_module_function"
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
library;

struct S {}

fn mod_fn() -> u8 {
S::S_ASSOC
}

impl S {
const S_ASSOC: u8 = mod_fn();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
category = "disabled" # TODO: Enable this failing test and write checks once https://github.com/FuelLabs/sway/issues/6539 is fixed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "recursive_const_module"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
name = "recursive_const_module"
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
library;

pub const A: u8 = B;
pub const B: u8 = A;

pub const X: u8 = Y;
pub const Y: u8 = Z;
pub const Z: u8 = X;
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
category = "fail" # TODO: Adjust these checks once https://github.com/FuelLabs/sway/issues/6534 is fixed.

# check: $()Type B is recursive via A, which is unsupported at this time.
# check: $()Type A is recursive via B, which is unsupported at this time.

# check: $()Type Y is recursive via Z and X, which is unsupported at this time.
# check: $()Type Z is recursive via X and Y, which is unsupported at this time.
# check: $()Type X is recursive via Y and Z, which is unsupported at this time.

# check: $()5 errors.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "recursive_const_module_over_associated_const"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
name = "recursive_const_module_over_associated_const"
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
library;

struct S {}

impl S {
const S_ASSOC: u8 = MOD_CONST;
}

const MOD_CONST: u8 = S::S_ASSOC;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
category = "fail"

#check: $()error
#check: $()const MOD_CONST: u8 = S::S_ASSOC;
#nextln: $()Could not find symbol "S_ASSOC" in this scope.

#check: $()error
#check: $()const MOD_CONST: u8 = S::S_ASSOC;
#nextln: $()Could not evaluate initializer to a const declaration.

#check: $()2 errors.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "recursive_const_module_over_associated_function"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
name = "recursive_const_module_over_associated_function"
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
library;

struct S {}

impl S {
fn assoc() -> u8 {
MOD_CONST
}
}

const MOD_CONST: u8 = S::assoc();
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
category = "fail"

#check: $()const MOD_CONST: u8 = S::assoc();
#nextln: $()No method named "assoc" found for type "S".

#check: $()const MOD_CONST: u8 = S::assoc();
#nextln: $()Could not evaluate initializer to a const declaration.

#check: $()2 errors.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "recursive_const_module_over_module_function"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
name = "recursive_const_module_over_module_function"
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
library;

fn mod_fn() -> u8 {
MOD_CONST
}

const MOD_CONST: u8 = mod_fn();
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
category = "fail"

#check: $()error
#check: $()const MOD_CONST: u8 = mod_fn();
#nextln: $()Could not find symbol "mod_fn" in this scope.

#check: $()error
#check: $()const MOD_CONST: u8 = mod_fn();
#nextln: $()Could not evaluate initializer to a const declaration.

#check: $()2 errors.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "recursive_const_stack_overflow"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
name = "recursive_const_stack_overflow"
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This test proves that https://github.com/FuelLabs/sway/issues/6540 is fixed.

library;

pub const MOD_FN: u8 = mod_fn();

fn mod_fn() -> u8 {
MOD_FN
}

struct S {}

impl S {
const S_ASSOC: u8 = MOD_CONST;
}

const MOD_CONST: u8 = S::S_ASSOC;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
category = "disabled" # TODO: Enable this failing test and write checks once https://github.com/FuelLabs/sway/issues/6540 is fixed.
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
script;
library;

enum E {
Eins: bool,
Zwei: u64,
Drei: E,
}

fn main() {

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
category = "fail"

# check: $()recursive types are not supported

# check: $()1 error.
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
script;
library;

struct S {
Eins: bool,
Zwei: u64,
Drei: S,
}

fn main() {

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
category = "fail"

# check: $()recursive types are not supported

# check: $()1 error.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
script;
library;

enum E {
Eins: F,
Expand Down Expand Up @@ -39,7 +39,3 @@ enum Y {
struct Z {
five: X,
}

fn main() {

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ category = "fail"
# check: $()Type Y is recursive via Z and X, which is unsupported at this time.
# check: $()Type Z is recursive via X and Y, which is unsupported at this time.
# check: $()Type X is recursive via Y and Z, which is unsupported at this time.

# check: $()10 errors.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
script;
library;

enum MyOption<T> {
Some: T,
Expand All @@ -13,5 +13,5 @@ fn bar<V>(value: V) -> MyOption<V> {
}

fn main() {
let x = bar(false);
let _ = bar(false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ category = "fail"
# nextln: $()expected: V
# nextln: $()found: MyOption<V>.
# nextln: $()Implicit return must match up with block's type.

# check: $()2 errors.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[package]]
name = "associated_const_in_decls_of_other_constants"
source = "member"
dependencies = ["std"]

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

[[package]]
name = "std"
source = "path+from-root-8CB91B60FB2568E4"
dependencies = ["core"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "associated_const_in_decls_of_other_constants"
implicit-std = false


[dependencies]
std = { path = "../../../../../../../sway-lib-std" }
Loading
Loading