Skip to content

Commit

Permalink
Fixes missing replace_decl for variable declarations. (#4777)
Browse files Browse the repository at this point in the history
## Description

We were not calling replace_decl for variable declarations.
This was making some trait method calls to not be replaced.

Unblocks #4701
Fixes #4773

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [ ] 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.
  • Loading branch information
esdrubal authored Jul 10, 2023
1 parent 2c6d410 commit 09ba6c6
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sway-core/src/language/ty/ast_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ impl ReplaceDecls for TyAstNode {
TyAstNodeContent::ImplicitReturnExpression(ref mut exp) => {
exp.replace_decls(decl_mapping, engines)
}
TyAstNodeContent::Declaration(TyDecl::VariableDecl(ref mut decl)) => {
decl.body.replace_decls(decl_mapping, engines);
}
TyAstNodeContent::Declaration(_) => {}
TyAstNodeContent::Expression(ref mut expr) => expr.replace_decls(decl_mapping, engines),
TyAstNodeContent::SideEffect(_) => (),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[package]]
name = 'core'
source = 'path+from-root-B5A424CFF35B4F1C'

[[package]]
name = 'generic_where_in_impl_self2'
source = 'member'
dependencies = ['std']

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

[dependencies]
std = { path = "../../../../../../../sway-lib-std" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"configurables": [],
"functions": [
{
"attributes": null,
"inputs": [],
"name": "main",
"output": {
"name": "",
"type": 0,
"typeArguments": null
}
}
],
"loggedTypes": [],
"messagesTypes": [],
"types": [
{
"components": null,
"type": "bool",
"typeId": 0,
"typeParameters": null
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
script;

use std::assert::*;

trait Trait {
#[inline(never)]
fn method(self) -> u64;
}

impl Trait for u64 {
#[inline(never)]
fn method(self) -> u64{
42
}
}

struct CallTrait<V> {}

#[inline(never)]
fn call_trait<T>(t: T) -> u64 where T: Trait {
t.method()
}

impl<K> CallTrait<K> where K: Trait {
pub fn call_trait(self, key: K) -> u64 {
let v = call_trait(key);
v
}
}

fn main() -> bool {
let _ = call_trait(1);
let ct = CallTrait::<u64> {};
assert(ct.call_trait(1) == 42);
true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
category = "run"
expected_result = { action = "return", value = 1 }
validate_abi = true

0 comments on commit 09ba6c6

Please sign in to comment.