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
The only way that this is possible, is if we use this(...), as every method is attached with an instance of some degree. If we use the type name, is will try to find it in the global scope, to which, it cannot. Currently, items will only be put into the global scope, if it's the main file in global scope, or an include is processed with no module alias. The compiler might need to get extra information, then infer that the type name should reference this instead, which will allow it to work as intended with the illusion of using the type name.
One issue with this approach, is that if we're referring to another type in the module, it will run into the same issue and won't work. Next solution would be to infer property accesses to get the type needed, but this will become difficult as it requires knowledge of all modules/structs it is nested within too.
// File a
struct Foo {
static fn new { Foo() };
}
// File b
include 'a' in a;
let a = a.Foo.new();
The text was updated successfully, but these errors were encountered:
Caleb-o
changed the title
Cannot instantiate struct inside self, if within module
Cannot instantiate struct inside self, if within module (from include)
Aug 3, 2023
The only way that this is possible, is if we use
this(...)
, as every method is attached with an instance of some degree. If we use the type name, is will try to find it in the global scope, to which, it cannot. Currently, items will only be put into the global scope, if it's the main file in global scope, or an include is processed with no module alias. The compiler might need to get extra information, then infer that the type name should referencethis
instead, which will allow it to work as intended with the illusion of using the type name.One issue with this approach, is that if we're referring to another type in the module, it will run into the same issue and won't work. Next solution would be to infer property accesses to get the type needed, but this will become difficult as it requires knowledge of all modules/structs it is nested within too.
The text was updated successfully, but these errors were encountered: