-
-
Notifications
You must be signed in to change notification settings - Fork 667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strict field initialization #1155
Conversation
This commit introduces strict field initialization. All fields must be definitely assigned through an initializer or within the constructor else, a compilation error will be reported. If the field is intended to be initialized later through dependency injection or a custom initialiazer, the field must be post-fixed with !
This commit add field initialization at the flow level. It also refactors the error reporting for uninitialized properties.
Flows was an interesting journey 😅 I've added support for conditional flows in the constructor in my last commits, in the test files you can find the use cases (https://github.com/AssemblyScript/assemblyscript/pull/1155/files#diff-5fa1688a93849f802b2ae2b7f3cbffe6R26) I realized that we need the same behaviour for |
- Use `actualFunction` to check for constructor flows - Fix compilation errors regarding boolean comparisons
It seems main reason on failure happened in |
Not necessarily, the error begins a few lines prior. Wondering how it is even able to print during console.log - as if inspecting would call something. |
I spent some time today on @MaxGraey's hint (debugging |
Don not skip property initialization even if expected to be initialized at the constructor level
Co-Authored-By: Max Graey <maxgraey@gmail.com>
Co-Authored-By: Max Graey <maxgraey@gmail.com>
Co-Authored-By: Max Graey <maxgraey@gmail.com>
So I was not terribly convinced that the fix that I introduced in 8c6a554 was the right way to go without knowing why. I've found the answer, it turns out that we're not compiling exported generic classes unless that this is done in a different code path or in a different way that I'm not aware of; that means that with the code that I had prior to 8c6a554 for a class like: export class C<T> {
prop: i32
} the compiler won't report any compilation errors and even worse it will skip the initialization of
|
What should happen currently is, if one has export class C<T> {
prop: i32
} there is nothing to export because we don't know what export class C<T> {
prop: i32
}
new C<i32>(); // here we know that there is indeed a class |
export class C<T> {
prop: i32
}
new C<i32>(); // here I guess even with this case we shouldn't export generics for host and throw the error / warning |
Hesitating a bit here due to all the |
This PR addresses #482
It introduces a new kind of flags:
FieldFlags
in order to track the state of each field per flow. Under the hood, field flags are represented asMap<string, FieldFlags>
in which each field is uniquely identified by its internal name. Field flags are only initialized when the current flow belongs to a constructor, in every other case they arenull
A general overview of the changes: