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

Propagation From Type Parameters #6379

Closed
IGI-111 opened this issue Aug 7, 2024 · 0 comments · Fixed by #6502
Closed

Propagation From Type Parameters #6379

IGI-111 opened this issue Aug 7, 2024 · 0 comments · Fixed by #6502
Assignees
Labels
audit-report Related to the audit report bug Something isn't working P: medium

Comments

@IGI-111
Copy link
Contributor

IGI-111 commented Aug 7, 2024

CS-FSSA-013

Sway's type system ignores some hints about the type of variables. Let us consider the following
example:

trait Build {
 fn build() -> Self;
}
fn produce<T>() -> T
where
 T: Build,
{
 T::build()
}
impl Build for u32 {
 fn build() -> Self {
 31
 }
}
impl Build for u64 {
 fn build() -> Self {
 63
 }
}
fn consume(a: u32) {}
fn main() {
 let x = produce();
 consume(x);
}

Here we instantiate variable x with the result of produce(). Since produce() returns a generic type,
the concrete type of x cannot be determined just yet: it can either be u64 or u32. Since x is later passed
to consume(), which only accepts u32, type inference should assign this type to x. However, the
compiler fails to use this information and rejects the program, as it assumes x to be of type u64.

@IGI-111 IGI-111 added bug Something isn't working P: medium audit-report Related to the audit report labels Aug 7, 2024
ironcev added a commit that referenced this issue Sep 6, 2024
## Description

This PR adds tests that prove that #6379 is fixed. The actual fix
happened in #6490.

Closes #6379.

## Checklist

- [x] I have linked to any relevant issues.
- [ ] 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.
- [ ] 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audit-report Related to the audit report bug Something isn't working P: medium
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants