-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Impl self methods not checking impl self constraints #5046
Labels
bug
Something isn't working
compiler: frontend
Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
compiler
General compiler. Should eventually become more specific as the issue is triaged
Comments
7 tasks
esdrubal
added
compiler
General compiler. Should eventually become more specific as the issue is triaged
compiler: frontend
Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
bug
Something isn't working
labels
Aug 28, 2023
Contrary to what is reported the following code does not compile and gives the expected error: struct MyStruct {
val: u64
}
abi MyContract {
#[storage(read, write)]
fn test_function();
}
storage {
my_map: StorageMap<MyStruct, u64> = StorageMap::<MyStruct, u64> {},
}
impl MyContract for Contract {
#[storage(read, write)]
fn test_function() {
let my_struct = MyStruct { val: 1 };
storage.my_map.insert(my_struct, 2)
}
}
The following code is also throwing the expected error: trait Hash {
fn hash(self) -> u64;
}
struct Struct<T> {
}
struct Struct2<T> {
}
struct StructHashable {
}
/*
impl Hash for StructHashable {
fn hash(self) -> u64 {
42
}
}
*/
impl<T> Struct<Struct2<T>> where T: Hash {
fn call_hash(self, hashable: T) -> u64 {
hashable.hash()
}
}
fn main() {
let a = Struct::<Struct2<StructHashable>> {};
let b = StructHashable {};
a.call_hash(b);
}
|
esdrubal
added a commit
that referenced
this issue
Sep 23, 2024
esdrubal
added a commit
that referenced
this issue
Sep 26, 2024
## Description The reproduction reported in #5046 is throwing the expected error. Closes #5046. ## 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). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [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 <joshpbatty@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
Something isn't working
compiler: frontend
Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
compiler
General compiler. Should eventually become more specific as the issue is triaged
As found by @bitzoic in #5045
This compiles:
When this does not, even though the
insert()
function uses the samesha256<T>()
function:Originally posted by @bitzoic in #5045 (comment)
Seems like
storage.my_map.insert(my_struct, 2)
should not compile because my_struct does not implement the Hash trait, the insert should inherit the constraints from the impl self but somehow it does not detect the missing constraint.The text was updated successfully, but these errors were encountered: