enhanced the compiler to prohibit variable declaration in class init scope
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@ -9,8 +9,10 @@ check_SCRIPTS = \
|
||||
va-01.hcl
|
||||
|
||||
check_ERRORS = \
|
||||
feed-01.err \
|
||||
var-01.err \
|
||||
var-02.err
|
||||
var-02.err \
|
||||
var-03.err
|
||||
|
||||
##noinst_SCRIPTS = $(check_SCRIPTS)
|
||||
EXTRA_DIST = $(check_SCRIPTS) $(check_ERRORS)
|
||||
|
@ -480,8 +480,10 @@ check_SCRIPTS = \
|
||||
va-01.hcl
|
||||
|
||||
check_ERRORS = \
|
||||
feed-01.err \
|
||||
var-01.err \
|
||||
var-02.err
|
||||
var-02.err \
|
||||
var-03.err
|
||||
|
||||
EXTRA_DIST = $(check_SCRIPTS) $(check_ERRORS)
|
||||
TEST_EXTENSIONS = .hcl .err
|
||||
|
8
t/err.sh
8
t/err.sh
@ -3,7 +3,7 @@
|
||||
for i in $@; do :; done
|
||||
script="$i"
|
||||
|
||||
expected_errinfo=$(grep -E "##[[:space:]]+ERROR:" "$script" 2>/dev/null)
|
||||
expected_errinfo=$(grep -n -o -E "##ERROR: .+" "$script" 2>/dev/null)
|
||||
[ -z "$expected_errinfo" ] && {
|
||||
echo "INVALID TESTER - $script contains no ERROR information"
|
||||
exit 1
|
||||
@ -11,11 +11,13 @@ expected_errinfo=$(grep -E "##[[:space:]]+ERROR:" "$script" 2>/dev/null)
|
||||
|
||||
expected_errline=$(echo $expected_errinfo | cut -d: -f1)
|
||||
xlen=$(echo $expected_errline | wc -c)
|
||||
xlen=$(expr $xlen + 2)
|
||||
xlen=$(expr $xlen + 10)
|
||||
expected_errmsg=$(echo $expected_errinfo | cut -c${xlen}-)
|
||||
|
||||
output=$($@ 2>&1)
|
||||
echo "$output" | grep -E "ERROR:.+${script}.+${expected_errmsg}" || {
|
||||
## the regular expression is not escaped properly. the error information must not
|
||||
## include specifial regex characters to avoid problems.
|
||||
echo "$output" | grep -E "ERROR:.+${script}\[${expected_errline},[[:digit:]]+\] ${expected_errmsg}" || {
|
||||
echo "$script - $output"
|
||||
exit 1
|
||||
}
|
||||
|
19
t/var-01.err
19
t/var-01.err
@ -1,14 +1,25 @@
|
||||
defclass Object {
|
||||
defclass A | a | {
|
||||
defun ::* init1() {
|
||||
| b |
|
||||
set b (+ 1 2);
|
||||
set a b;
|
||||
printf "init to %d\n" a;
|
||||
return self;
|
||||
};
|
||||
|
||||
{
|
||||
## this must not be allowed at this level. if it's allowed,
|
||||
## it should be at the top-level which is above the class level. this is confusing.
|
||||
| j | ## ERROR: syntax error
|
||||
| j | ##ERROR: syntax error - variable declaration disallowed in class init scope
|
||||
set j 20;
|
||||
printf ">>> %d\n" j;
|
||||
}
|
||||
|
||||
defun ::* init() {
|
||||
printf "Object init...\n";
|
||||
defun ::* init2() {
|
||||
| b |
|
||||
set b (+ 10 20);
|
||||
set a b;
|
||||
printf "init to %d\n" a;
|
||||
return self;
|
||||
};
|
||||
};
|
||||
|
@ -1,3 +1,3 @@
|
||||
## if you want local temporaries variables at the top-level, use the blocked expression.
|
||||
| a | ## ERROR: syntax error - variable declaration disallowed
|
||||
set a 10;
|
||||
| a | ##ERROR: syntax error - variable declaration disallowed
|
||||
set a 10;
|
||||
|
Reference in New Issue
Block a user