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

Make sure to always ACCEPT the enum elements. #869

Merged
merged 1 commit into from Sep 5, 2016
Merged

Make sure to always ACCEPT the enum elements. #869

merged 1 commit into from Sep 5, 2016

Conversation

LemonBoy
Copy link
Contributor

@LemonBoy LemonBoy commented Sep 5, 2016

As shown in RT#129160 if we try to use an enumeration element as a type
for an optional parameter like in the following example we end up with a
type mismatch between Int:D and Foo.
To actually understand what goes wrong we simply have to look at the
backtrace: the ACCEPT method that the binder calls is the one from the
Numeric role (since enums have Int as base type by default) which in
turn calls the infix:<==> operator which in turn calls Bridge.
This is where things go south as we actually fail to bind a (Option)
type object to a Int:D, causing the error shown in the bug report.
The solution is to simply catch this edge case and let the base type
handle all the other ones in a similar manner to what we already do for
Bool.

enum Options(<Foo Bar>); (sub f(Foo $o?){ ... })()

Some additional tests to show how the enum behave, compared with Bool

use Test;
ok Bool.ACCEPTS(True);
ok True.ACCEPTS(Bool);
enum En(<Foo>);
ok En.ACCEPTS(Foo);
ok Foo.ACCEPTS(En);

As shown in RT#129160 if we try to use an enumeration element as a type
for an optional parameter like in the following example we end up with a
type mismatch between Int:D and Foo.
To actually understand what goes wrong we simply have to look at the
backtrace: the ACCEPT method that the binder calls is the one from the
Numeric role (since enums have Int as base type by default) which in
turn calls the infix:<==> operator which in turn calls Bridge.
This is where things go south as we actually fail to bind a (Option)
type object to a Int:D, causing the error shown in the bug report.
The solution is to simply catch this edge case and let the base type
handle all the other ones in a similar manner to what we already do for
Bool.

enum Options(<Foo Bar>); (sub f(Foo $o?){ ... })()
@lizmat lizmat merged commit bdd4691 into rakudo:nom Sep 5, 2016
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.

None yet

2 participants