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

Type inference regression for Vec in forc 0.62.0+ #6487

Closed
Lukasz2891 opened this issue Sep 2, 2024 · 0 comments · Fixed by #6526
Closed

Type inference regression for Vec in forc 0.62.0+ #6487

Lukasz2891 opened this issue Sep 2, 2024 · 0 comments · Fixed by #6526
Assignees
Labels
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen

Comments

@Lukasz2891
Copy link

Related Component

compiler

Problem

library;

use std::vec::*;

impl<T> Vec<T> {
    pub fn with(self, value: T) -> Self {
        let mut vec = self;
        vec.push(value);

        vec
    }
}

#[test]
fn test_with_two_values() {
    let data = Vec::new().with(0x333u256).with(0x222u256);

    assert(data.len() == 2);
}

gives the following error:

error
   --> .../.forc/git/checkouts/std-9be0d6062747ea7/f55c81cce61aac31913ac0e87306cbaed7da679a/sway-lib-std/src/vec.sw:144:16
    |
142 | 
143 | /// A contiguous growable array type, written as `Vec<T>`, short for 'vector'. It has ownership over its buffer.
144 | pub struct Vec<T> {
    |                ^ Cannot infer type for type parameter "T". Insufficient type information provided. Try annotating its type.
145 |     buf: RawVec<T>,
146 |     len: u64,
    |
____

error
  --> .../.forc/git/checkouts/std-9be0d6062747ea7/f55c81cce61aac31913ac0e87306cbaed7da679a/sway-lib-std/src/vec.sw:33:26
   |
31 | 
32 |         Self {
33 |             ptr: alloc::<T>(0),
   |                          ^ Cannot infer type for type parameter "T". Insufficient type information provided. Try annotating its type.
34 |             cap: 0,
35 |         }
   |
____

error
   --> .../.forc/git/checkouts/std-9be0d6062747ea7/f55c81cce61aac31913ac0e87306cbaed7da679a/sway-lib-std/src/vec.sw:172:9
    |
170 | 
171 |     pub fn new() -> Self {
172 |         Self {
    |         ^^^^ Cannot infer type for type parameter "T". Insufficient type information provided. Try annotating its type.
173 |             buf: RawVec::new(),
174 |             len: 0,
    |
____

Steps

Use the code as above.

The code works properly with forc 0.61.0 but doesn't for 0.62.0+++.

Possible Solution(s)

    let data = Vec::<u256>::new().with(0x333u256).with(0x222u256);

solves the issue

Notes

No response

Installed components

[toolchain]
channel = "testnet"

[components]
fuel-core = "0.35.0"
forc = "0.63.3"
@Lukasz2891 Lukasz2891 added bug Something isn't working triage This issue was opened with a template and needs to be triaged by code owners. labels Sep 2, 2024
@IGI-111 IGI-111 added compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen and removed triage This issue was opened with a template and needs to be triaged by code owners. labels Sep 2, 2024
xunilrj added a commit that referenced this issue Sep 11, 2024
## Description

This PR fixes #6487.

## 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.
- [ ] 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
bug Something isn't working compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants