-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Do not bail generating base type initializer in the presence of use site warnings #76347
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14073,6 +14073,51 @@ public static void Main() | |
CompileAndVerify(comp, verify: Verification.Skipped, expectedOutput: "123").VerifyDiagnostics(); | ||
} | ||
|
||
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/72357")] | ||
public void CopyCtor_AssemblyWarnings() | ||
333fred marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
var comp1 = CreateCompilation(""" | ||
public record BaseRecord | ||
{ | ||
public required object Object1 { get; init; } | ||
public required object Object2 { get; init; } | ||
} | ||
""", assemblyName: "Base", targetFramework: TargetFramework.Net70); | ||
|
||
var comp2 = CreateCompilation(""" | ||
var sut = new DerivedRecord | ||
{ | ||
Object1 = new object(), | ||
Object2 = new object() | ||
}; | ||
|
||
var broken = sut with { Object2 = new object()}; | ||
System.Console.Write(broken.Object1 is null); | ||
|
||
public record DerivedRecord : BaseRecord; | ||
""", assemblyName: "Derived", references: [comp1.EmitToImageReference()], targetFramework: TargetFramework.Net80); | ||
|
||
var verifier = CompileAndVerify(comp2, expectedOutput: ExecutionConditionUtil.IsCoreClr ? "False" : null, verify: Verification.FailsPEVerify); | ||
333fred marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is specifically .NET 8, I don't think all mono environments would work, so I only did |
||
|
||
// Historical note: These warnings were the cause of the bug, so they are not being suppressed | ||
var expectedDiagnostic = | ||
// warning CS1701: Assuming assembly reference 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' used by 'Base' matches identity 'System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' of 'System.Runtime', you may need to supply runtime policy | ||
Diagnostic(ErrorCode.WRN_UnifyReferenceMajMin).WithArguments("System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "Base", "System.Runtime, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Runtime").WithLocation(1, 1); | ||
|
||
verifier.VerifyDiagnostics(Enumerable.Repeat(expectedDiagnostic, 21).ToArray()); | ||
|
||
verifier.VerifyIL("DerivedRecord..ctor(DerivedRecord)", """ | ||
{ | ||
// Code size 8 (0x8) | ||
.maxstack 2 | ||
IL_0000: ldarg.0 | ||
IL_0001: ldarg.1 | ||
IL_0002: call "BaseRecord..ctor(BaseRecord)" | ||
IL_0007: ret | ||
} | ||
"""); | ||
} | ||
|
||
[Fact] | ||
public void Deconstruct_Simple() | ||
{ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
There are lots of uses of this method, but this was the only one that did something conditional. That seemed like a bad thing to keep around, so I just made the method return
void
instead to prevent something like this from happening again.