Skip to content

Can't bind type-parametric functions to function arguments #898

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
jruderman opened this issue Sep 10, 2011 · 1 comment
Closed

Can't bind type-parametric functions to function arguments #898

jruderman opened this issue Sep 10, 2011 · 1 comment

Comments

@jruderman
Copy link
Contributor

Ran into this while trying to generalize the "steal_exprs" part of my fuzzer.

fn safe_to_steal(e: &@ast::expr) -> bool {
    alt e.node {
        _ { true }
    }
}

fn stash_if<T>(c: fn(&@T)->bool, es: @mutable [T], e: &@T) {
    if c(e) {
        *es += [*e];
    }
}

fn steal_exprs(crate: &ast::crate) -> [ast::expr] {
    let exprs: @mutable [ast::expr] = @mutable [];
    let v = visit::mk_simple_visitor(@{
      visit_expr: bind stash_if(safe_to_steal, exprs, _)
      with *visit::default_simple_visitor()
    });
    visit::visit_crate(crate, (), v);;
    *exprs
}

Here's a simpler testcase that also demonstrates the problem:

fn even(e: &int) -> bool {
    e % 2 == 0
}

fn log_if<T>(c: fn(&T)->bool, e: &T) {
    if c(e) { log e }
}

fn main() {
    (bind log_if(even, _))(2);
}

Both the fuzzer piece and the simpler testcase result in:

Assertion failed: ((i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && "Calling a function with a bad signature!"), function init, file Instructions.cpp, line 274.

If I remove the ampersands from the simpler testcase, I get a different LLVM assertion:

Assertion failed: (S->getType()->isPointerTy() && "Invalid cast"), function CreatePointerCast, file Instructions.cpp, line 2334.
@brson brson closed this as completed in f480203 Oct 11, 2011
@brson
Copy link
Contributor

brson commented Oct 12, 2011

Seems to be fixed.

lkuper added a commit that referenced this issue Oct 12, 2011
This reverts commit f480203.

Oops.  This patch requires people to bump their LLVM version.
lkuper added a commit that referenced this issue Oct 12, 2011
This reverts commit e305ab3.

Oops again.  Reverting a mistaken revert.
arielb1 pushed a commit to arielb1/rust that referenced this issue Apr 10, 2015
Minor fixups to 0231-upvar-capture-inference.md.
ZuseZ4 pushed a commit to EnzymeAD/rust that referenced this issue Mar 7, 2023
coastalwhite pushed a commit to coastalwhite/rust that referenced this issue Aug 5, 2023
This reverts commit 311d56c.

Co-authored-by: Jethro Beekman <jethro@fortanix.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants