make even negative sign not allow any type

This commit is contained in:
2023-06-21 08:58:13 +01:00
parent 6495e7f9b9
commit ae08f059fb
2 changed files with 6 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ var negativeCompile = makeRegex(`( *)-(.|\n)+( *)`)
type negative struct {
VAL any
sign bool
line int
code string
path string
@@ -26,11 +27,9 @@ func parseNegative(code UNPARSEcode, index int, codeline []UNPARSEcode) (any, bo
path: code.path,
}, index, codeline, 0)
if difference%2 == 0 {
return resp, worked, err, i
}
return negative{
VAL: resp,
sign: difference%2 == 0,
line: code.line,
code: code.realcode,
path: code.path,

View File

@@ -70,8 +70,11 @@ func runVal(line any, stack stack, stacklevel int) (any, ArErr) {
}
switch y := resp.(type) {
case number:
if !x.sign {
return newNumber().Neg(y), ArErr{}
}
return y, ArErr{}
}
return nil, ArErr{
TYPE: "TypeError",
message: "cannot negate a non-number",