From 91f8245a0c90e7388bd4cc86a00314ca08c0636e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?fn=20=E2=8C=83=20=E2=8C=A5?= <70830482+FnControlOption@users.noreply.github.com> Date: Mon, 24 Oct 2022 07:52:17 -0700 Subject: [PATCH] class.c (mrb_instance_alloc): raise error if NilClass/FalseClass. MRB_TT_FALSE is equal to 0, so we have to explicitly check if the class is either NilClass or FalseClass. --- src/class.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/class.c b/src/class.c index 2b90db58b..dfec8c5eb 100644 --- a/src/class.c +++ b/src/class.c @@ -1939,7 +1939,12 @@ mrb_instance_alloc(mrb_state *mrb, mrb_value cv) if (c->tt == MRB_TT_SCLASS) mrb_raise(mrb, E_TYPE_ERROR, "can't create instance of singleton class"); - if (ttype == 0) ttype = MRB_TT_OBJECT; + if (c == mrb->nil_class || c == mrb->false_class) { + mrb_assert(ttype == 0); + } + else if (ttype == 0) { + ttype = MRB_TT_OBJECT; + } if (ttype <= MRB_TT_CPTR) { mrb_raisef(mrb, E_TYPE_ERROR, "can't create instance of %v", cv); }