Skip to content

Commit

Permalink
Support where-free subsets
Browse files Browse the repository at this point in the history
These are essentially like type aliases. This patch unlocks the forms:

- subset MyInt of Int
- my Int subset MyInt
  • Loading branch information
ab5tract committed Feb 12, 2023
1 parent 7b4e982 commit d3d839c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Raku/Actions.nqp
Expand Up @@ -1711,7 +1711,7 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions {
method type_declarator:sym<subset>($/) {
my $decl := self.r('Type', 'Subset').new(
:name($<longname>.ast),
:where($<EXPR>.ast),
:where($<EXPR> ?? $<EXPR>.ast !! Mu),
:traits($<trait>),
:scope($*SCOPE)
);
Expand Down
20 changes: 11 additions & 9 deletions src/Raku/ast/type.rakumod
Expand Up @@ -350,7 +350,7 @@ class RakuAST::Type::Subset

method visit-children(Code $visitor) {
$visitor($!name);
$visitor($!where);
$visitor($!where) if $!where;
# External constants break if visited with missing IMPL-QAST-DECL. Adding a sensible IMPL-QAST-DECL
# results in lexical declarations for things like Int, which will break if added more than once.
$visitor($!of) if $!of && !nqp::istype($!of, RakuAST::Declaration::External::Constant);
Expand Down Expand Up @@ -394,7 +394,7 @@ class RakuAST::Type::Subset
}

my $block;
if !$!where.IMPL-CURRIED && (!nqp::istype($!where, RakuAST::Code) || nqp::istype($!where, RakuAST::RegexThunk)) {
if $!where && !$!where.IMPL-CURRIED && (!nqp::istype($!where, RakuAST::Code) || nqp::istype($!where, RakuAST::RegexThunk)) {
$block := RakuAST::Block.new(
body => RakuAST::Blockoid.new(
RakuAST::StatementList.new(
Expand Down Expand Up @@ -447,12 +447,14 @@ class RakuAST::Type::Subset
if $!of {
$type.HOW.set_of($type, $!of.compile-time-value);
}
$type.HOW.set_where(
$type,
$!where.IMPL-CURRIED
?? $!where.IMPL-CURRIED.meta-object
!! $!where.compile-time-value
);
if $!where {
$type.HOW.set_where(
$type,
$!where.IMPL-CURRIED
?? $!where.IMPL-CURRIED.meta-object
!! $!where.compile-time-value
);
}
$type
}
}
}

0 comments on commit d3d839c

Please sign in to comment.