kinx

Looks like JavaScript, feels like Ruby, and it is a script language fitting in C programmers.

This project is maintained by Kray-G

Bug Fixes

Overview

This section describes a testing for bug fixes.

Examples

Example 1. isPrime in native

This bug’s was caused by an invalid mod operation.

See also an additional test code in Basic Expressions in native.

Code

native isPrime(n: int) {
    for (var i = 2; i <= Math.sqrt(n); ++i) {
        if (n % i == 0) return false;
    }
    return true;
}

System.println(isPrime(15) ? 'true' : 'false'); // false
System.println(isPrime(17) ? 'true' : 'false'); // true

Result

false
true

Example 2. Integer multiply by -1

This was found internally, so there is no issue id.

Code

for (ypix in 0...24) {
    System.print(":");
    var y = ypix / 12 - 1;
    for (xpix in 1...79) {
        var x = xpix / 30 - 2;
        var x0 = x;
        var y0 = y;
        var iter = 0;
        while (iter < 11 && x0 * x0 + y0 * y0 <= 4) {
            var x1 = (x0 * x0) - (y0 * y0) + x;
            var y1 = 2 * x0 * y0 + y;
            x0 = x1;
            y0 = y1;
            iter = iter + 1;
        }
        System.print(*(" .-:;+=xX$& "[iter]));
    }
    System.println("");
}

Result

:        .......------------------------:::::::::;;;;+=X X & ;:::::::------....
:      ......------------------------::::::::::;;;;+==x&  &x=+;;;::::::-------.
:     ....------------------------::::::::::;;;;++=X         X=;;;;;:::::------
:    ...-----------------------::::::::::;;+++++==xX         Xx=+++;;;;;:::----
:   ..----------------------::::::::;;;;+x   &XX               & $x===x +;::---
:  ..--------------------::::;;;;;;;;+++=x&                             $+;::--
: ..----------------::::;;;;;;;;;;++++=x$                              $=+;;::-
: .-----------:::::;;= x+++++++++====xx&                               &xx+;:::
:.-----:::::::::;;;++=$  &$X$ &XXXxxXX&                                   x+;::
:---:::::::::;;;;;;+==X$            &                                    &=;;::
:-::::::::;;;;;;+=xxX$                                                   x+;;::
:::;;:::++++++==xX&                                                     =+;;;::
:                                                                     Xx=+;;;::
:::;;:::++++++==xX&                                                     =+;;;::
:-::::::::;;;;;;+=xxX$                                                   x+;;::
:---:::::::::;;;;;;+==X$            &                                    &=;;::
:.-----:::::::::;;;++=$  &$X$ &XXXxxXX&                                   x+;::
: .-----------:::::;;= x+++++++++====xx&                               &xx+;:::
: ..----------------::::;;;;;;;;;;++++=x$                              $=+;;::-
:  ..--------------------::::;;;;;;;;+++=x&                             $+;::--
:   ..----------------------::::::::;;;;+x   &XX               & $x===x +;::---
:    ...-----------------------::::::::::;;+++++==xX         Xx=+++;;;;;:::----
:     ....------------------------::::::::::;;;;++=X         X=;;;;;:::::------
:      ......------------------------::::::::::;;;;+==x&  &x=+;;;::::::-------.

Example 3. Comparing between variables of a string

This bug’s was caused by missing implementation.

Code

function gt(a, b)  { return a > b; }
function lt(a, b)  { return a < b; }
function ge(a, b)  { return a >= b; }
function le(a, b)  { return a <= b; }
function lge(a, b) { return a <=> b; }
try { gt("a", "b");  System.println("Successful"); } catch (e) { System.println(e.what()); }
try { lt("a", "b");  System.println("Successful"); } catch (e) { System.println(e.what()); }
try { ge("a", "b");  System.println("Successful"); } catch (e) { System.println(e.what()); }
try { le("a", "b");  System.println("Successful"); } catch (e) { System.println(e.what()); }
try { lge("a", "b"); System.println("Successful"); } catch (e) { System.println(e.what()); }

Result

Successful
Successful
Successful
Successful
Successful

Example 4. Can’t specify a return type of function

This bug’s was caused by lack of consideration of a part of type propagation.

Code

class A() {
    public xxx() {
        System.println("Successful");
    }
}

function f(): A {
    return new A(); // => Error: Expect return type (object) but (... unknown)
}
f().xxx();

Result

Successful

Example 5. Comparison Failure & Crash

This bug’s was caused by lack of the code which moves to the next opcode.

Code

function test1(a) { return 10 >= a; }
function test2(a) { return -1 <= a; }
function test3(a) { return 100 < a; }

System.println(test1(10.5));
System.println(test2(10.5));
System.println(test3(10.5));

Result

0
1
0

Example 6. Fails a Destructuring Assignment in Const

This bug’s was caused by an incorrect bytecode.

Code

function test1(data) {
    var [a, b, ...c] = data.split(',');
}
function test2(data) {
    [a, b, ...c] = data.split(',');
}
function test3(data) {
    const [a, b, ...c] = data.split(',');
}
test1("1,2,3,4,5,6,7,8,9");
test2("1,2,3,4,5,6,7,8,9");
test3("1,2,3,4,5,6,7,8,9");

System.println("Successful");

Result

Successful

Example 7. Fixed toJsonString() for Object

This bug’s was caused by incorrect extracting an object.

Code

class A {
    public toString() { return "A"; }
}
class B {
    public toString() { return "\\\"B\""; }
}

System.println({ a: new A() });  // => {"a":"A"}
System.println({ b: new B() });  // => {"a":"A"}

Result

{"a":"A"}
{"b":"\\\"B\""}

Example 8. Detects error for multi decl of ‘const’

This bug’s was caused by missing to check the condition.

Code

const A = 1;
const A = 2;
A = 3;
System.println(A);

Result

Error: Symbol(A) has been already declared as 'const' near the <test.kx>:2
Error: Can not assign a value to the 'const' variable near the <test.kx>:3

Example 9. Pin operator in declaration.

This bug’s was caused by handling with pinned as a const.

Code

var a = 10;
var { x: ^a, y } = { x: 10, y: 100 };
System.println(y);
var { x: ^a, y } = { x: 100, y: 100 };
System.println(y);

Result

100
Uncaught exception: No one catch the exception.
NoMatchingPatternException: Pattern not matched
Stack Trace Information:
        at <main-block>(test.kx:4)

Example 10. Pin operator in function arguments.

This bug’s was caused by the incorrect scope for a variable with pin operator in function arguments.

Code

var a = 10;
function test({ x: ^a, y }) {   // The variable `a` should be handled
                                //  as an outside variable by a lexical scope.
    return y;
}
System.println(test({ x: 10, y: 100 }));
System.println(test({ x: 100, y: 100 }));

Result

100
Uncaught exception: No one catch the exception.
NoMatchingPatternException: Pattern not matched
Stack Trace Information:
        at function test(test.kx:2)
        at <main-block>(test.kx:7)

Example 11. Fixed SegFault on Linux

This bug’s was caused by NULL dereference only with a Linux code.

Code

var t = $env.NO_ENVVAR;
System.println("t = ", t);

Result

t =

Example 12. Stack overflow with =~ or !~

This bug’s was caused by missing a pop operation.

Code

var l = "aaaaaaa";
for (var i = 0; i < 1000; ++i) {
    if (g = (l =~ /([b-z]+)/)) {
        System.println(g[1].string);
    } else if (g = (l =~ /([0-9]+)/)) {
        System.println(g[1].string);
    }
}
System.println("Successful");

Result

Successful

Example 13. Crash in native.

This bug’s was caused by dereferencing uninitialized variable pointer.

Code

var mem = [];
for (var i = 0; i < 10; ++i) {
    mem[i] = i;
}

native func0(n:int):obj {
    var r:int[];
    for (var i = 0; i < n; ++i) {
        r[i] = mem[i];
    }
    return r;
}
var res = func0(10);
System.println(res);

native func1(n:int):bin {
    var r:bin;
    for (var i = 0; i < n; ++i) {
        r[i] = mem[i];
    }
    return r;
}
var res = func1(10);
System.println(res);

Result

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
<0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09>