So this one took a bit to narrow down, but I think I have found a bug where the reference count of shared types aren't counted correctly when assigning handles to implemented interfaces.
There's different errors that we've ran into, but for me the most reproducible one is this:
main.as (22, 1) : INFO : Compiling void Test()
main.as (23, 5) : ERR : No matching signatures to 'Bar::Foo(const int)'
main.as (23, 5) : INFO : Candidates are:
main.as (23, 5) : INFO : void Foo()Where Foo is another unreferenced shared class. I don't have a minimal reproduction here yet, but the code for Foo is pretty straightforward:
// If `Foo` is not in the `Bar` namespace, the error doesn't reproduce
namespace Bar {
// `Foo` is only defined and used here
shared class Foo {
Foo(int) {}
}
}
void Test() {
Bar::Foo(2);
}Anyway, all the code above by itself is not a problem. It becomes a problem as soon as we assign a handle in another module, and ALSO when another completely unrelated module is unloaded:
// Module A:
shared interface IMedal {}
IMedal@ g_foo;
array<IMedal@> g_foos;
void setMedal(IMedal@ medal) {
@g_foo = medal; // Without this, everything is fine
//g_foos.InsertLast(medal); // Interestingly, uncommenting this seems to stop the error again -- potentially this adds an extra reference to the shared type again?
}
// Module B:
shared interface IMedal {}
import void setMedal(IMedal@ medal) from "UME";
class MyMedal : IMedal {}
MyMedal@ g_medal;
void Main() {
@g_medal = MyMedal();
setMedal(g_medal);
}My guess is that the unrelated module unloading is causing some references to be cleared, and because there's not enough references on the shared type, we now get compiler errors because something was freed?
Sorry this bugreport is so vague, I'm still trying to wrap my head around it and get a minimal reproduction :( I'm kinda hoping this might be just enough information to go on 😅
Sometimes we get the error that the declaration is different in another module, even though all modules have been unloaded and reloaded, meaning shared types are definitely leaking somehow. For more context, see: https://github.com/openplanet-nl/issues/issues/451