From 0e2dfea7fb695ff55bb5d7086c30133431913b1d Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 22 Jul 2024 18:28:21 +0900 Subject: [PATCH] added more test-cases for class redefintion --- lib/exec.c | 2 ++ t/class-5001.err | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/lib/exec.c b/lib/exec.c index fed6651..802cd4f 100644 --- a/lib/exec.c +++ b/lib/exec.c @@ -3559,10 +3559,12 @@ static int execute (hcl_t* hcl) /* store or pop */ if (HCL_IS_CLASS(hcl, ass->cdr) && ((hcl_oop_class_t)ass->cdr)->name == ass->car) { + /* the existing value must be a class. disallow re-definition */ hcl_seterrbfmt (hcl, HCL_EPERM, "prohibited redefintion of %.*js", HCL_OBJ_GET_SIZE(ass->car), HCL_OBJ_GET_CHAR_SLOT(ass->car)); if (do_throw_with_internal_errmsg(hcl, fetched_instruction_pointer) >= 0) break; goto oops_with_errmsg_supplement; } + ass->cdr = HCL_STACK_GETTOP(hcl); if ((bcode >> 2) & 1) diff --git a/t/class-5001.err b/t/class-5001.err index 7820cd4..d9d9e9b 100644 --- a/t/class-5001.err +++ b/t/class-5001.err @@ -147,3 +147,41 @@ class X [ a b c ] { } } } + +--- + +class F { +} + +class F { ##ERROR: exception not handled - "prohibited redefintion of F +} + +--- + +class F { +} + +F := 30 ##ERROR: exception not handled - "prohibited redefintion of F + +--- + + +class F { +} + +F := (class { ##ERROR: exception not handled - "prohibited redefintion of F" +}) + +--- + +F := (class { +}) + +F := (class F { ##ERROR: exception not handle - "prohibited redefintion of F" +}) + +## TDOO: do we need to allow the above? + +##F := 30 +##class F { ##ERROR: exception not handled - "prohibited redefintion of F" +##}