Skip to content

Fill out test plan for auto-default structs#60688

Merged
RikkiGibson merged 8 commits intodotnet:mainfrom
RikkiGibson:auto-default-test-plan
Apr 22, 2022
Merged

Fill out test plan for auto-default structs#60688
RikkiGibson merged 8 commits intodotnet:mainfrom
RikkiGibson:auto-default-test-plan

Conversation

@RikkiGibson
Copy link
Member

@RikkiGibson RikkiGibson commented Apr 11, 2022

Closes #60167 (test plan)

I'm not sure how to test the LangVersion warnings here, as it requires having a struct with private reference type fields in another assembly, but I did test it manually. langversion-warning

I manually verified in the debugger that changing an auto-defaulted field's value, then dragging to the { of the constructor, causes default to get written to the field again. auto-default-debugger

@ghost ghost added the Area-Compilers label Apr 11, 2022
@RikkiGibson RikkiGibson marked this pull request as ready for review April 14, 2022 22:25
@RikkiGibson RikkiGibson requested review from a team as code owners April 14, 2022 22:25
@RikkiGibson
Copy link
Member Author

Bleh, the fix for sequence points effectively means I need to change a lot of test baselines. Going to draft for now.

@RikkiGibson RikkiGibson marked this pull request as draft April 14, 2022 22:42
@jcouv jcouv self-assigned this Apr 15, 2022
@RikkiGibson RikkiGibson marked this pull request as ready for review April 18, 2022 19:53
@RikkiGibson
Copy link
Member Author

@jcouv @cston this is ready for review.

@cston
Copy link
Contributor

cston commented Apr 20, 2022

I'm not sure how to test the LangVersion warnings here, as it requires having a struct with private reference type fields in another assembly

Is the question how to write an "upgrade project" test with multiple projects? It looks like there are examples such as UpgradeProjectForSealedToStringInRecords_CS8912.

IL_0008: ret
}
");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

Consider testing S1 = default; as well.


comp = CreateCompilation(source);
comp.VerifyDiagnostics();
}
Copy link
Contributor

@cston cston Apr 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

Consider testing #pragma warning disable 9022 as well, with and without WithSpecificDiagnosticOptions(ReportStructInitializationWarnings).

@RikkiGibson
Copy link
Member Author

RikkiGibson commented Apr 20, 2022

I'm not sure how to test the LangVersion warnings here, as it requires having a struct with private reference type fields in another assembly

Is the question how to write an "upgrade project" test with multiple projects? It looks like there are examples such as UpgradeProjectForSealedToStringInRecords_CS8912.

I poked at this a bit more but I wasn't able to get the warning wave diagnostic to show up. Not sure why. It does work in manual testing.

        [Fact]
        public async Task UpgradeProjectForStructAutoDefaultError_4()
        {
            await TestLanguageVersionUpgradedAsync(
@"
<Workspace>
    <Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"" LanguageVersion=""10"">
        <Document FilePath=""Derived.cs"">
public struct S1
{
    private object objectField;
}
        </Document>
    </Project>
    <Project Language=""C#"" AssemblyName=""Assembly2"" CommonReferences=""true"" LanguageVersion=""10"">
        <ProjectReference>Assembly1</ProjectReference>
        <Document FilePath=""Base.cs"">
public struct S2
{
    public S1 structField;
    public [|S2|](bool unused) { }
}
        </Document>
    </Project>
</Workspace>
",
                expected: LanguageVersion.Preview,
                new CSharpParseOptions(LanguageVersion.CSharp10),
                // also added as a parameter to 'TestLanguageVersionUpgradedAsync' and threaded through
                new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, warningLevel: 9999));

@jcouv jcouv added the Area-IDE label Apr 20, 2022
Diagnostics.Add(
ErrorCode.ERR_UseDefViolationThisUnsupportedVersion,
node.Location,
thisParameter.Name,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I wonder if our diagnostic infrastructure should/could have caught that, the same way that it verifies that all parts are "printable".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the DiagnosticInfo constructor should verify args.Length - 1 matches the largest index in the message.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Filed #60862


[Theory]
[InlineData(LanguageVersion.CSharp10)]
[InlineData(LanguageVersion.Latest)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: probably should be Preview or Next, we don't really use Latest much

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks (iteration 7). Left a couple of comments for nits

@RikkiGibson
Copy link
Member Author

@dotnet/roslyn-ide for review of IDE-specific changes

Copy link
Contributor

@sharwell sharwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDE side looks fine. Would be good to add remaining tests if possible.

}",
expected: LanguageVersion.Preview,
new CSharpParseOptions(LanguageVersion.CSharp10));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭 It looks like there are 6 new error cases added, but only 3 tested.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see #60688 (comment)

@RikkiGibson RikkiGibson merged commit 7555dc6 into dotnet:main Apr 22, 2022
@RikkiGibson RikkiGibson deleted the auto-default-test-plan branch April 22, 2022 19:52
@ghost ghost added this to the Next milestone Apr 22, 2022
@dibarbet dibarbet modified the milestones: Next, 17.3.P1 Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test plan for "auto-default structs"

5 participants