Skip to content
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

static constructors are ommited to process alltogether #98

Closed
cyborgyn opened this issue Oct 6, 2021 · 2 comments
Closed

static constructors are ommited to process alltogether #98

cyborgyn opened this issue Oct 6, 2021 · 2 comments

Comments

@cyborgyn
Copy link

cyborgyn commented Oct 6, 2021

In the following static class initialization:

    static class Foo
    {
        public static string Bar;
        static Foo()
        {
            Bar = "foobar";
        }
    }

Foo.Bar will never contain a value, the string "foobar" is not enlisted between constant strings, and related to #97 issue, no static constructor is generated, but called.

@cyborgyn
Copy link
Author

cyborgyn commented Oct 6, 2021

Actually, it seems to be that easy to fix, as the following patch suggests. Is there a not so obvious reason why static constructors were filtered out during C code generation?

diff --git "a/IL2C.Core/AssemblyPreparer.cs" "b/IL2C.Core/AssemblyPreparer.cs"
index 12389a6..49d824f 100644
--- "a/IL2C.Core/AssemblyPreparer.cs"
+++ "b/IL2C.Core/AssemblyPreparer.cs"
@@ -322,7 +322,7 @@ namespace IL2C
                 // All types
                 type => true,
                 // The methods except type initializer.
-                method => !(method.IsConstructor && method.IsStatic));
+                method => true);
         }
     }
 }

@kekyo
Copy link
Owner

kekyo commented May 28, 2022

@cyborgyn Sorry for the very delay. I understood #100 work and imported it with cherry-pick. 2cbb6f1

For the life of me, I can't remember why I excluded the Type initializer; it may have been due to the fact that I had not checked the initialization order of the Type initializer. (I still have not been able to confirm this.)
If the initialization order is affected by the ECMA335 specification, I may need to rework this area, but for now, I'll leave it at that.

@kekyo kekyo closed this as completed May 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants