summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorKoichi Sasada <[email protected]>2024-04-15 17:06:03 +0900
committerKoichi Sasada <[email protected]>2024-04-15 17:56:49 +0900
commit9a57b047033034c30a3351d08ad648735299c8cf (patch)
tree1c77a91b5749d7f047963dda354edbc7298f484e /compile.c
parent145cced9bcb6a52fccfa0c669121bd07d3b3ff74 (diff)
`super{}` doesn't use block
`super(){}`, `super{}` and `super(&b)` doesn't use the given block so warn unused block warning when calling a method which doesn't use block with above `super` expressions. e.g.: `def f = super{B1}` (warn on `f{B2}` because `B2` is not used.
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/compile.c b/compile.c
index 30321a7af8..0fb3b85583 100644
--- a/compile.c
+++ b/compile.c
@@ -9369,10 +9369,10 @@ compile_super(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, i
unsigned int flag = 0;
struct rb_callinfo_kwarg *keywords = NULL;
const rb_iseq_t *parent_block = ISEQ_COMPILE_DATA(iseq)->current_block;
+ int use_block = 1;
INIT_ANCHOR(args);
ISEQ_COMPILE_DATA(iseq)->current_block = NULL;
- ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.flags.use_block = 1;
if (type == NODE_SUPER) {
VALUE vargc = setup_args(iseq, args, RNODE_SUPER(node)->nd_args, &flag, &keywords);
@@ -9381,6 +9381,10 @@ compile_super(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, i
if ((flag & VM_CALL_ARGS_BLOCKARG) && (flag & VM_CALL_KW_SPLAT) && !(flag & VM_CALL_KW_SPLAT_MUT)) {
ADD_INSN(args, node, splatkw);
}
+
+ if (flag & VM_CALL_ARGS_BLOCKARG) {
+ use_block = 0;
+ }
}
else {
/* NODE_ZSUPER */
@@ -9474,6 +9478,10 @@ compile_super(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, i
}
}
+ if (use_block && parent_block == NULL) {
+ ISEQ_BODY(ISEQ_BODY(iseq)->local_iseq)->param.flags.use_block = 1;
+ }
+
flag |= VM_CALL_SUPER | VM_CALL_FCALL;
if (type == NODE_ZSUPER) flag |= VM_CALL_ZSUPER;
ADD_INSN(ret, node, putself);