You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code, similar to issue #340, crashes the clever.
import std.*;
class ClassA {
private var func;
function ClassA() {
this.func = [];
}
function addFunc(f) {
this.func.append(f);
}
function run() {
io:println("+ Calling the B's function.");
this.func.each(function (x) { x(); });
}
}
class ClassB {
private var instanceOfA;
private var x;
private function foobar() {
io:println("[B] It should show 'bar' now:");
io:println('[B] x => ' + this.x['foo']);
io:println('Did it work?');
}
function ClassB(_ia, _x) {
this.instanceOfA = _ia;
this.x = _x;
this.instanceOfA.addFunc(this.foobar);
}
}
var a = ClassA.new();
var b = ClassB.new(a, {'foo':'bar'});
a.run();
On GDB:
(gdb) r foo.clv
Starting program: /home/ricardo/Development/Github/clever-rgsilva/clever foo.clv
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
+ Calling the B's function.
[B] It should show 'bar' now:
Program received signal SIGSEGV, Segmentation fault.
0x00000000004f1aea in clever::TypeObject::initialize (this=0x0, type=0x7e9050) at /home/ricardo/Development/Github/clever-rgsilva/./core/type.h:108
108 if (!m_initialized) {
(gdb) bt
#0 0x00000000004f1aea in clever::TypeObject::initialize (this=0x0, type=0x7e9050) at /home/ricardo/Development/Github/clever-rgsilva/./core/type.h:108
#1 0x00000000004effb8 in clever::VM::run (this=0x7fffffffe570) at /home/ricardo/Development/Github/clever-rgsilva/core/vm.cc:861
#2 0x00000000004e6d3d in clever::VM::runFunction (this=0x7fffffffe570, func=0x7e8a50, args=std::vector of length 1, capacity 1 = {...})
at /home/ricardo/Development/Github/clever-rgsilva/core/vm.cc:272
#3 0x000000000051975d in clever::ArrayType::each (this=0x7b9250, result=0x7c0310, obj=0x7c3110, args=std::vector of length 0, capacity 2, clever=0x7fffffffe6c0)
at /home/ricardo/Development/Github/clever-rgsilva/modules/std/core/array.cc:296
#4 0x00000000004ee416 in clever::VM::run (this=0x7fffffffe570) at /home/ricardo/Development/Github/clever-rgsilva/core/vm.cc:741
---Type <return> to continue, or q <return> to quit---
#5 0x00000000004c407b in clever::Interpreter::execute (this=0x7fffffffe700, interactive=false) at /home/ricardo/Development/Github/clever-rgsilva/core/driver.cc:51
#6 0x00000000004c3547 in main (argc=1, argv=0x7fffffffea00) at /home/ricardo/Development/Github/clever-rgsilva/core/main.cc:156
The text was updated successfully, but these errors were encountered:
A reduced version of the problem (which isn't related to map at all):
import std.*;
class ClassA {
var f;
function ClassA(b) {
this.f = [];
this.f.append(b);
}
function foo() {
this.f.each(function (x) { x(); });
}
}
class ClassB {
var x;
function ClassB() {
this.x = 'OK';
}
function foo() {
io:println(this.x);
}
}
var b = ClassB.new();
var a = ClassA.new(b.foo);
a.foo();
This happens because we tried to call a non-static method without the instance. For example, this works:
import std.*;
class ClassA {
var f;
function ClassA(b) {
this.f = [];
this.f.append(b);
}
function foo() {
this.f.each(function (x) { x(); });
}
}
class ClassB {
var x;
function ClassB() {
this.x = 'OK';
}
function foo() {
io:println('aba');
}
}
var b = ClassB.new();
var a = ClassA.new(b.foo);
a.foo();
Because in ClassB.foo() we don't have the this dereference thus making the method "static".
Nevertheless, this should be fixed.
This code, similar to issue #340, crashes the clever.
On GDB:
The text was updated successfully, but these errors were encountered: