Skip to content

[BUG] e is func is false #689

Open
Open

Description

@ntrel

Describe the bug
With cppfront from git ecd3726 and g++ (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0:

pred: (x: int) -> int = x < 20;

main: () = 
{
    p2 := :(x) -> _ = x < 20;
    b := 5 is (p2); // true
    std::cout << b << "\n";
    b = 5 is (pred); // false
    std::cout << b << "\n";
}

I expected both is expressions to produce true, but the second one is false.

A secondary problem is that rewriting pred to be a template fails to compile:

pred: (x) -> _ = x < 20;
lessthan.cpp2:48:17: error: no matching function for call to ‘is(int, <unresolved overloaded function type>)’
... snip candidates ...

Activity

  1. JohelEGP commented on Sep 18, 2023

    @JohelEGP
    Contributor

    The reason seems to be

    else if constexpr (requires{ bool{ value(x) }; }) {

    pred returns an int, so bool{pred(5)} is narrowing, and the requires-expression evaluates to false.

  2. ntrel commented on Sep 18, 2023

    @ntrel
    ContributorAuthor

    Oops, thanks! So this definition works:

    pred: (x: int) -> _ = x < 20;

    The remaining problem is if I don't specify a type for x then it doesn't compile.

  3. filipsajdak commented on Sep 19, 2023

    @filipsajdak
    Contributor

    I am currently working on is improvements. I will push it soon.

  4. filipsajdak commented on Sep 19, 2023

    @filipsajdak
    Contributor

    OK, I have solved also the generic function case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions