Skip to content
Permalink
Browse files

Add Enumeration role value comparison methods in predictable order

Needed for making rakudo and module builds reproducible.
  • Loading branch information...
niner committed May 1, 2019
1 parent a2ba573 commit 4af81c36d4c75c946bd19dc6d4ec89d055934dde
Showing with 5 additions and 3 deletions.
  1. +1 −1 src/Perl6/Metamodel/EnumHOW.nqp
  2. +4 −2 src/core/Enumeration.pm6
@@ -167,7 +167,7 @@ class Perl6::Metamodel::EnumHOW
method set_composalizer($c) { $composalizer := $c }
method composalize($obj) {
unless $!roled {
$!role := $composalizer($obj, self.name($obj), %!values);
$!role := $composalizer($obj, self.name($obj), @!enum_value_list);
$!roled := 1;
}
$!role
@@ -102,12 +102,14 @@ sub ENUM_VALUES(*@args) {
)
}

Metamodel::EnumHOW.set_composalizer(-> $type, $name, %enum_values {
Metamodel::EnumHOW.set_composalizer(-> $type, $name, @enum_values {
my Mu $r := Metamodel::ParametricRoleHOW.new_type(:name($name));
$r.^add_attribute(Attribute.new(
:name('$!' ~ $name), :type(nqp::decont($type)),
:has_accessor(1), :package($r)));
for %enum_values.kv -> $key, $value {
for @enum_values {
my $key = $_.key;
my $value = $_.value;
my $meth = method () { self."$name"() == $value }
$meth.set_name($key);
$r.^add_method($key, $meth);

0 comments on commit 4af81c3

Please sign in to comment.
You can’t perform that action at this time.