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

Bool ~~ BooleanEnum returns true #4134

Open
Leont opened this issue Dec 22, 2020 · 8 comments
Open

Bool ~~ BooleanEnum returns true #4134

Leont opened this issue Dec 22, 2020 · 8 comments
Labels
tests needed Issue is generally resolved but tests were not written yet

Comments

@Leont
Copy link
Contributor

Leont commented Dec 22, 2020

The Problem

For any enum that contains a Boolean value, e.g. enum BooleanEnum (:!Lies, :Truth), matching a boolean against that enum's type object will return true even though the boolean is not an enum

Expected Behavior

True ~~ BooleanEnum returns False

Actual Behavior

True ~~ BooleanEnum returns True

Environment

Welcome to Rakudo(tm) v2020.12.
Implementing the Raku(tm) programming language v6.d.
Built on MoarVM version 2020.12.
@vrurg
Copy link
Member

vrurg commented Dec 22, 2020

The observed behavior is correct. The point is:

say BooleanEnum.^mro; # ((Bool) (Bool) (Int) (Cool) (Any) (Mu))

The only thing which confuses me here is the first (Bool) because normally it should be the enum itself:

enum SS (:a(3e0), :b(4e0));
say SS.^mro; # ((SS) (Num) (Cool) (Any) (Mu))

But otherwise the pattern of enum having the base type of its values is followed as expected.

@Leont
Copy link
Contributor Author

Leont commented Dec 22, 2020

The observed behavior is correct. The point is:

say BooleanEnum.^mro; # ((Bool) (Bool) (Int) (Cool) (Any) (Mu))

I'm not sure what point you're trying to make here.

The only thing which confuses me here is the first (Bool) because normally it should be the enum itself:

enum SS (:a(3e0), :b(4e0));
say SS.^mro; # ((SS) (Num) (Cool) (Any) (Mu))

But otherwise the pattern of enum having the base type of its values is followed as expected.

Apparently:

raku -e 'enum Foo (:Truth); dd Foo.WHAT, Truth.WHAT'
Bool
Bool

Which would explain the observed behavior, but raises a bunch of new questions at the same time.

@jnthn
Copy link
Member

jnthn commented Dec 22, 2020

An enumeration type is a subtype of the type of its values (which should all have a consistent type, otherwise it's an error).

@Leont
Copy link
Contributor Author

Leont commented Dec 22, 2020

An enumeration type is a subtype of the type of its values (which should all have a consistent type, otherwise it's an error).

I get that. I totally expect BooleanEnum ~~ Bool, but the other way around should be false. And it is false for all other types AFAICT.

@vrurg
Copy link
Member

vrurg commented Dec 22, 2020

My apologies, there is actually a problem. Apparently, BooleanEnum must be a type on its own akin to SS from my example. Besides, SS behaves as expected:

say 3e0 ~~ SS; # False

The same should be expected for True ~~ BooleanEnum.

@jnthn
Copy link
Member

jnthn commented Dec 22, 2020

but the other way around should be false

Goodness, I managed to do the same thinko as @vrurg. At least I'm in good company... :-)

@2colours
Copy link
Contributor

Apparently, this issue has been fixed in the meantime:

https://gist.github.com/Whateverable/f0e879eb4cfc6ce67c9dbc144a1b1c41
https://gist.github.com/Whateverable/7759c03d6978abeff0fdc5dc3d152927
Bisects to this commit:
9f80771

@Leont Do you think this issue can be closed now?

@vrurg vrurg added the tests needed Issue is generally resolved but tests were not written yet label Dec 12, 2022
@vrurg
Copy link
Member

vrurg commented Dec 12, 2022

We need a test for this case first. Resolution of this issue was unintentional, no specific test has been done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests needed Issue is generally resolved but tests were not written yet
Projects
None yet
Development

No branches or pull requests

4 participants