Skip to content

Commit

Permalink
Potential 6.d impl of default defaults for DefiniteHOWs
Browse files Browse the repository at this point in the history
Would probably take care of #1493
(need to be tested)
  • Loading branch information
zoffixznet committed Feb 7, 2018
1 parent 2847e50 commit 11e6d5e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Perl6/World.nqp
Expand Up @@ -1622,7 +1622,7 @@ class Perl6::World is HLL::World {
%info<bind_constraint> := self.parameterize_type_with_args($/,
%info<bind_constraint>, [$vtype], nqp::hash());
%info<value_type> := $vtype;
%info<default_value> := $vtype;
%info<default_value> := self.maybe-definite-how-base: $vtype;
}
else {
%info<container_type> := %info<container_base>;
Expand Down Expand Up @@ -1689,7 +1689,8 @@ class Perl6::World is HLL::World {
%info<bind_constraint> := self.parameterize_type_with_args($/,
%info<bind_constraint>, @value_type, nqp::hash());
%info<value_type> := @value_type[0];
%info<default_value> := @value_type[0];
%info<default_value>
:= self.maybe-definite-how-base: @value_type[0];
}
else {
%info<container_type> := %info<container_base>;
Expand Down Expand Up @@ -1730,7 +1731,8 @@ class Perl6::World is HLL::World {
if @value_type {
%info<bind_constraint> := @value_type[0];
%info<value_type> := @value_type[0];
%info<default_value> := @value_type[0];
%info<default_value>
:= self.maybe-definite-how-base: @value_type[0];
}
else {
%info<bind_constraint> := self.find_symbol(['Mu'], :setting-only);
Expand All @@ -1741,6 +1743,13 @@ class Perl6::World is HLL::World {
}
%info
}
method maybe-definite-how-base ($v) {
# returns the value itself, unless it's a DefiniteHOW, in which case,
# it returns its base type
nqp::eqaddr($v.HOW,
$*W.find_symbol: ['Metamodel','DefiniteHOW'], :setting-only
) ?? $v.HOW.base_type: $v !! $v
}

# Installs one of the magical lexicals ($_, $/ and $!). Uses a cache to
# avoid massive duplication of containers and container descriptors.
Expand Down

2 comments on commit 11e6d5e

@jnthn
Copy link
Member

@jnthn jnthn commented on 11e6d5e Feb 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we were to do this conditional on the language version being parsed, this could go into master (behind v6.d.PREVIEW, I'd think?

@zoffixznet
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that should be so. I just let it marinate for now, in case anyone wanted to object to this change.

Please sign in to comment.