From a2b840f41d29332e309fd693c32374d9d4b6a28d Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 20 Oct 2024 20:12:31 +0900 Subject: [PATCH] updated add_class_level_variable() for better duplicate check --- lib/comp.c | 9 +++++---- t/class-5001.err | 7 +++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/comp.c b/lib/comp.c index 2a7728e..2cb4f13 100644 --- a/lib/comp.c +++ b/lib/comp.c @@ -295,14 +295,15 @@ static void fini_class_level_variable_buffer (hcl_t* hcl, hcl_oocsc_t* dst) } } -static int add_class_level_variable (hcl_t* hcl, hcl_oocsc_t* dst, const hcl_cnode_t* var, const hcl_bch_t* desc) +static int add_class_level_variable (hcl_t* hcl, hcl_oocsc_t* dst, hcl_oocsc_t* altdst, const hcl_cnode_t* var, const hcl_bch_t* desc) { /* it downcasts hcl_oocsc_t* to hcl_oocs_t*. take extra care to keep their type defintion * compatible for downcasting in hcl-cmn.h */ hcl_oocs_t* name; name = HCL_CNODE_GET_TOK(var); - if (__find_word_in_string((hcl_oocs_t*)dst, name, 0, HCL_NULL) >= 0) + if (__find_word_in_string((hcl_oocs_t*)dst, name, 0, HCL_NULL) >= 0 || + (__find_word_in_string((hcl_oocs_t*)altdst, name, 0, HCL_NULL) >= 0)) { hcl_setsynerrbfmt ( hcl, HCL_SYNERR_VARNAMEDUP, HCL_CNODE_GET_LOC(var), HCL_NULL, @@ -3801,7 +3802,7 @@ static int compile_var (hcl_t* hcl, hcl_cnode_t* src) goto oops; } - if (add_class_level_variable(hcl, &cbi->ivars, tmp, "instance") <= -1) goto oops; + if (add_class_level_variable(hcl, &cbi->ivars, &cbi->cvars, tmp, "instance") <= -1) goto oops; cbi->nivars++; } else @@ -3815,7 +3816,7 @@ static int compile_var (hcl_t* hcl, hcl_cnode_t* src) goto oops; } - if (add_class_level_variable(hcl, &cbi->cvars, tmp, "class") <= -1) goto oops; + if (add_class_level_variable(hcl, &cbi->cvars, &cbi->ivars, tmp, "class") <= -1) goto oops; cbi->ncvars++; } diff --git a/t/class-5001.err b/t/class-5001.err index 1dff216..c09da1e 100644 --- a/t/class-5001.err +++ b/t/class-5001.err @@ -289,11 +289,14 @@ class Kuduro [a b c] { } --- -class Kuduru [a [b] c] { + +class Kuduro [a [b] c] { var d e - var b ##TODO: should this be prohibited? + var b ##ERROR: syntax error - duplicate instance variable name 'b' } +--- + class Kuduro [a [b] c] { var d e var(#class) b ##ERROR: syntax error - duplicate class variable name 'b'