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

[BUG] e is func is false #689

Open
ntrel opened this issue Sep 18, 2023 · 4 comments
Open

[BUG] e is func is false #689

ntrel opened this issue Sep 18, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@ntrel
Copy link
Contributor

ntrel commented Sep 18, 2023

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 ...
@ntrel ntrel added the bug Something isn't working label Sep 18, 2023
@JohelEGP
Copy link
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.

@ntrel
Copy link
Contributor Author

ntrel commented Sep 18, 2023

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.

@filipsajdak
Copy link
Contributor

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

@filipsajdak
Copy link
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
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants