Skip to content

Commit

Permalink
Fix for node dependency order for enum instantiations. (#1036)
Browse files Browse the repository at this point in the history
  • Loading branch information
otrho authored Mar 27, 2022
1 parent 5740e38 commit 546df70
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
8 changes: 6 additions & 2 deletions sway-core/src/semantic_analysis/node_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,14 @@ impl Dependencies {
})
}
Expression::SubfieldExpression { prefix, .. } => self.gather_from_expr(prefix),
Expression::DelineatedPath { call_path, .. } => {
Expression::DelineatedPath {
call_path, args, ..
} => {
// It's either a module path which we can ignore, or an enum variant path, in which
// case we're interested in the enum name, ignoring the variant name.
// case we're interested in the enum name and initialiser args, ignoring the
// variant name.
self.gather_from_call_path(call_path, true, false)
.gather_from_iter(args.iter(), |deps, arg| deps.gather_from_expr(arg))
}
Expression::MethodApplication { arguments, .. } => {
self.gather_from_iter(arguments.iter(), |deps, arg| deps.gather_from_expr(arg))
Expand Down
4 changes: 4 additions & 0 deletions test/src/e2e_vm_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ pub fn run(filter_regex: Option<regex::Regex>) {
"should_pass/language/generic_impl_self",
ProgramState::Return(10),
),
(
"should_pass/language/enum_init_fn_call",
ProgramState::Return(1),
),
];

let mut number_of_tests_run = positive_project_names.iter().fold(0, |acc, (name, res)| {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = 'enum_init_fn_call'
dependencies = []
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
entry = "main.sw"
license = "Apache-2.0"
name = "enum_init_fn_call"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
script;

enum A {
A: u64,
}

fn main() -> u64 {
if let A::A(n) = A::A(f()) { n } else { 0 }
}

fn f() -> u64 {
1
}

0 comments on commit 546df70

Please sign in to comment.