Skip to content

Add is overload for free function predicate #669

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

Conversation

filipsajdak
Copy link
Contributor

@filipsajdak filipsajdak commented Sep 9, 2023

The current implementation of is does not handle generic functions as predicates.

The following case works:

less_than_10_a: (i : int) -> bool = i < 10;

main: () = {
  12 is (less_than_10_a);
}

It works also when the function has a generic return type:

less_than_10_b: (i : int) -> _ = i < 10;

main: () = {
  12 is (less_than_10_b);
}

But, it does not work when the function has a generic argument. The following case does not work:

less_than_10_c: (i) -> _ = i < 10;

main: () = {
  12 is (less_than_10_c); // error
}

This change introduces additional overload for is, making the free function predicates acceptable by is (the function needs to return bool or generic type). That makes the following cases work:

less_than_10_c: (i) -> _ = i < 10;
less_than_10_d: (i) -> bool = i < 10;

main: () = {
  5 is (less_than_10_c); // works
  2 is (less_than_10_d); // works
}

Functions that return other types than bool or auto do not work.

All regression tests pass. Add a test for this case and update the regression test results.

@filipsajdak filipsajdak force-pushed the fsajdak-add-is-overload-for-free-function-predicate branch from 54f10df to ec413e8 Compare September 9, 2023 22:15
Current implementation of `is` does not handle generic functions as predicates.

The following case works:
```cpp
less_than_10_a: (i : int) -> bool = i < 10;

main: () = {
  12 is (less_than_10_a);
}
```

It work also when function has generic return type
```cpp
less_than_10_b: (i : int) -> _ =  i < 10;

main: () = {
  12 is (less_than_10_b);
}
```

It does not work when function has generic argument.
The following case does not work:
```cpp
less_than_10_c: (i) -> _ = i < 10;

main: () = {
  12 is (less_than_10_c); // error
}
```

This change introduce additional overload for `is` making free function
predicates acceptable by `is` (the function needs to return
`bool` or generic type). That makes the following cases to work:
```cpp
less_than_10_c: (i) -> _ = i < 10;
less_than_10_d: (i) -> bool = i < 10;

main: () = {
  5 is (less_than_10_c); // works
  2 is (less_than_10_d); // works
}
```

Functions that return other type then `bool` or `auto` do not work.
@filipsajdak
Copy link
Contributor Author

I am closing this one as it is covered by #701

@filipsajdak filipsajdak closed this Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants