-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Test netmodules containing module initializers #44228
Test netmodules containing module initializers #44228
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace System.Runtime.CompilerServices { public class ModuleInitializerAttribute : System.Attribute { } }"; | ||
var comp1 = CreateCompilation(s1, options: TestOptions.ReleaseModule.WithModuleName("A"), parseOptions: s_parseOptions); | ||
comp1.VerifyDiagnostics(); | ||
var ref1 = comp1.EmitToImageReference(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var ref1 = comp1.EmitToImageReference(); [](start = 12, length = 40)
I think for each compilation we want to verify whether we emit the <Module>..cctor
#Closed
var comp6 = CreateCompilation(s6, options: TestOptions.ReleaseExe.WithModuleName("C"), parseOptions: s_parseOptions, references: new[] { ref1, ref2 }); | ||
comp6.VerifyDiagnostics(); | ||
CompileAndVerify(comp6, expectedOutput: "13"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} [](start = 8, length = 1)
I think it would be good to cover scenarios when the main module of the assembly also has an initializer. #Closed
Done with review pass (iteration 1) #Closed |
[ModuleInitializer] | ||
public static void Init() | ||
{ | ||
Console.Write(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 [](start = 22, length = 1)
Does this number conflict with the one printed by ref1
? Please use unique numbers to avoid any confusion. #Closed
void validateNoModuleInitializer(ModuleSymbol module) | ||
{ | ||
var moduleType = module.ContainingAssembly.GetTypeByMetadataName("<Module>"); | ||
Assert.Null(moduleType.GetMember<MethodSymbol>(".cctor")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert.Null(moduleType.GetMember(".cctor")); [](start = 16, length = 58)
Please add Assert.Equal(MetadataImportOptions.All, ((PEModuleSymbol)module).ImportOptions);
as we do in other similar validators. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (iteration 2), with a couple of suggestions for the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (iteration 3)
…yn into mi-netmodules
Related to #40500.
Test based on
CompilationEmitTests.MultipleNetmodulesWithAnonymousTypes
.Will think on whether there are more netmodule scenarios we need to test.