Skip to content

Instantly share code, notes, and snippets.

@ufobat
Created July 2, 2017 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ufobat/92a4eead04bbfae235d2a292c44c0276 to your computer and use it in GitHub Desktop.
Save ufobat/92a4eead04bbfae235d2a292c44c0276 to your computer and use it in GitHub Desktop.
> cat A.pm
class A { ... }
role R {
has A $!private;
method r {
self!s;
}
method !s {
$!private!s if $!private;
say $.b;
}
method set_private(A $a) {
self!private = $a;
}
}
class A does R {
has Str $.b = "secret";
};
> cat B.pm
use v6;
use A;
class B does R {
method b { self.r }
method setup { $!private = A.new; return self }
}
> perl6 -I. -e 'use A; use B; my $b = B.new; $b.set_private(A.new); $b.r'
No such private method '!!private' for invocant of type 'B'
in method set_private at /home/martin
@ufobat
Copy link
Author

ufobat commented Jul 2, 2017

- QAST::CompUnit  :W<?> :UNIT<?>
  [pre_deserialize]
    - QAST::Stmt 
      - QAST::Stmt 
        - QAST::Op(loadbytecode) 
          - QAST::VM 
            [jvm]
              - QAST::SVal(ModuleLoader.class) 
            [moar]
              - QAST::SVal(ModuleLoader.moarvm) 
        - QAST::Op(callmethod load_module) 
          - QAST::Op(gethllsym) 
            - QAST::SVal(nqp) 
            - QAST::SVal(ModuleLoader) 
          - QAST::SVal(Perl6::ModuleLoader) 
      - QAST::Op(forceouterctx) 
        - QAST::BVal(2) 
        - QAST::Op(callmethod load_setting) 
          - QAST::Op(getcurhllsym) 
            - QAST::SVal(ModuleLoader) 
          - QAST::SVal(CORE) 
  [post_deserialize]
    - QAST::Stmts 
      - QAST::Op(bind) 
        - QAST::Var(attribute $!do) 
          - QAST::WVal(Block) 
          - QAST::WVal(Code) 
        - QAST::BVal(1) 
    - QAST::Op(bindcurhllsym) 
      - QAST::SVal(GLOBAL) 
      - QAST::WVal(GLOBAL) 
  [load]
    - QAST::Op(call) 
      - QAST::BVal(2) 
  [children]
    - QAST::Block  :in_stmt_mod<?> use A; use B; my $b = B.new; $b.set_private(A.new)...
      - QAST::Var(local __args__ :decl(param)) 
      - QAST::Stmts  use A; use B; my $b = B.new; $b.set_private(A.new)...
      - QAST::Op(call) 
        - QAST::Block(:blocktype(declaration_static))  :IN_DECL<mainline> :in_stmt_mod<?> :code_object<?> :outer<?>
          - QAST::Stmts  use A; use B; my $b = B.new; $b.set_private(A.new)...
            - QAST::Var(lexical $b :decl(contvar)) 
            - QAST::Var(lexical $¢ :decl(contvar)) 
            - QAST::Var(lexical $! :decl(contvar)) 
            - QAST::Var(lexical $/ :decl(contvar)) 
            - QAST::Var(lexical $_ :decl(contvar)) 
            - QAST::Var(lexical GLOBALish :decl(static)) 
            - QAST::Var(lexical EXPORT :decl(static)) 
            - QAST::Var(lexical $?PACKAGE :decl(static)) 
            - QAST::Var(lexical ::?PACKAGE :decl(static)) 
            - QAST::Var(lexical $=finish :decl(static)) 
            - QAST::Var(lexical A :decl(static)) 
            - QAST::Var(lexical R :decl(static)) 
            - QAST::Var(lexical B :decl(static)) 
            - QAST::Var(lexical $=pod :decl(static)) 
              [value]
                - 
            - QAST::Var(lexical !UNIT_MARKER :decl(static)) 
          - QAST::VM 
            [jvm]
              - QAST::Op(null) 
            [moar]
              - QAST::Op(null) 
            [loadlibs]
              - nqp_group nqp_ops perl6_ops bit_ops math_ops trans_ops io_ops obscure_ops os file sys_ops nqp_bigint_ops nqp_dyncall_ops
          - QAST::Stmts 
            - QAST::Op(bind) 
              - QAST::Var(local ctxsave :decl(var)) 
              - QAST::Var(contextual $*CTXSAVE) 
            - QAST::Op(unless) 
              - QAST::Op(isnull) 
                - QAST::Var(local ctxsave) 
              - QAST::Op(if) 
                - QAST::Op(can) 
                  - QAST::Var(local ctxsave) 
                  - QAST::SVal(ctxsave) 
                - QAST::Op(callmethod ctxsave) 
                  - QAST::Var(local ctxsave) 
          - QAST::Stmts 
            - QAST::WVal(Array) 
            - QAST::Stmts <sunk> use A; use B; my $b = B.new; $b.set_private(A.new)...
              - QAST::Stmt <sunk> use A
                - QAST::WVal(Nil)  :statement_id<?>
              - QAST::Stmt <sunk> use B
                - QAST::WVal(Nil)  :statement_id<?>
              - QAST::Stmt <sunk> my $b = B.new
                - QAST::Op(assign)  :statement_id<?>
                  - QAST::Var(lexical $b) <wanted sinkok> $b
                  - QAST::Op(hllize) <wanted>
                    - QAST::Op(callmethod new)  new
                      - QAST::WVal(B) <wanted> B
              - QAST::Stmt <sunk> $b.set_private(A.new)
                - QAST::Want <sunk>
                  - QAST::Op(callmethod sink) <sunk>
                    - QAST::Op(hllize) <sunk> :statement_id<?>
                      - QAST::Op(callmethod set_private)  A.new
                        - QAST::Var(lexical $b) <wanted> $b
                        - QAST::Op(hllize) 
                          - QAST::Op(callmethod new)  new
                            - QAST::WVal(A) <wanted> A
                  - v
                  - QAST::Op(p6sink) 
                    - QAST::Op(hllize) <sunk> :statement_id<?>
                      - QAST::Op(callmethod set_private)  A.new
                        - QAST::Var(lexical $b) <wanted> $b
                        - QAST::Op(hllize) 
                          - QAST::Op(callmethod new)  new
                            - QAST::WVal(A) <wanted> A
              - QAST::Stmt <sunk final> $b.r
                - QAST::Want <sunk>
                  - QAST::Op(callmethod sink) <sunk>
                    - QAST::Op(hllize) <sunk> :statement_id<?>
                      - QAST::Op(callmethod r)  r
                        - QAST::Var(lexical $b) <wanted> $b
                  - v
                  - QAST::Op(p6sink) 
                    - QAST::Op(hllize) <sunk> :statement_id<?>
                      - QAST::Op(callmethod r)  r
                        - QAST::Var(lexical $b) <wanted> $b
            - QAST::WVal(Nil) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment