Rust-GCC / Rust-GCC/gccrs

closure type inference bug

Open
#2,827 1 comment 0 reactions 1 assignee View on GitHub

@philberty is already working on this.

Since Feb 3, 2024.

bug typechecking
Dominant language
C++
Stars
2.9k
Forks
231
Avg merge
19h 55m
Merged PRs (30d)
67

Description

I tried this code: https://godbolt.org/z/aKPfG1Khf

#[lang = "sized"]
pub trait Sized {}

#[lang = "fn_once"]
pub trait FnOnce<Args> {
    #[lang = "fn_once_output"]
    type Output;

    extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
}

pub fn test() {
    let add: fn(&i32, &i32) -> i32 = |x, y| {
    	*x + *y
    };
}

I expected to see this happen: compile without error

Instead, this happened:

x86-64 GCCRS (GCCRS master) - 579ms

<source>:15:16: error: expected reference type got T?
   15 |         *x + *y
      |                ^
<source>:15:21: error: expected reference type got T?
   15 |         *x + *y
      |                     ^
<source>:15:16: error: cannot apply this operator to types <tyty::error> and <tyty::error>
   15 |         *x + *y
      |                ^
<source>:14:5: error: bounds not satisfied for fnptr (& i32 ,& i32 ,) -> i32 'FnOnce' is not satisfied [E0277]
   14 |     let add: fn(&i32, &i32) -> i32 = |x, y| {
      |     ^~~    
Meta
  • What version of Rust GCC were you using, git sha if possible.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.