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

Add MetadataAsSource test for records #59736

Merged
merged 1 commit into from
Feb 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,117 @@ public void F()

await GenerateAndVerifySourceAsync(metadataSource, symbolName, LanguageNames.CSharp, languageVersion: "Preview", metadataLanguageVersion: "Preview", expected: expected, signaturesOnly: signaturesOnly);
}

[Theory, CombinatorialData, Trait(Traits.Feature, Traits.Features.MetadataAsSource)]
[WorkItem(44566, "https://github.com/dotnet/roslyn/issues/44566")]
public async Task TestRecordType(bool signaturesOnly)
{
var metadataSource = "public record R;";
var symbolName = "R";

var expected = signaturesOnly switch
{
true => $@"#region {FeaturesResources.Assembly} ReferencedAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// {CodeAnalysisResources.InMemoryAssembly}
#endregion

#nullable enable

using System;
using System.Runtime.CompilerServices;
using System.Text;

public record [|R|] : IEquatable<R>
{{
public R();
[CompilerGenerated]
protected R(R original);
Comment on lines +470 to +471
Copy link
Member Author

@Youssef1313 Youssef1313 Feb 24, 2022

Choose a reason for hiding this comment

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

Is it expected to show up given the declaration is already "record"? This applies to other members as well


protected virtual Type EqualityContract {{ get; }}

[CompilerGenerated]
public virtual R <Clone>$();
[CompilerGenerated]
public override bool Equals(object? obj);
[CompilerGenerated]
public virtual bool Equals(R? other);
[CompilerGenerated]
public override int GetHashCode();
[CompilerGenerated]
public override string ToString();
[CompilerGenerated]
protected virtual bool PrintMembers(StringBuilder builder);

[CompilerGenerated]
public static bool operator ==(R? left, R? right);
[CompilerGenerated]
public static bool operator !=(R? left, R? right);
}}",
false => $@"#region {FeaturesResources.Assembly} ReferencedAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// {CodeAnalysisResources.InMemoryAssembly}
// Decompiled with ICSharpCode.Decompiler {ICSharpCodeDecompilerVersion}
#endregion

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;

public record [|R|]
Copy link
Member Author

Choose a reason for hiding this comment

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

Should this show : IEquatable<R>?

{{
[CompilerGenerated]
public override string ToString()
{{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append(""R"");
stringBuilder.Append("" {{ "");
if (PrintMembers(stringBuilder))
{{
stringBuilder.Append(' ');
}}

stringBuilder.Append('}}');
return stringBuilder.ToString();
}}

[CompilerGenerated]
protected virtual bool PrintMembers(StringBuilder builder)
{{
return false;
}}

[CompilerGenerated]
public override int GetHashCode()
{{
return EqualityComparer<Type>.Default.GetHashCode(EqualityContract);
}}

[CompilerGenerated]
public virtual bool Equals(R? other)
{{
return (object)this == other || ((object)other != null && EqualityContract == other!.EqualityContract);
}}

[CompilerGenerated]
protected R(R original)
{{
}}

public R()
{{
}}
}}
#if false // {CSharpEditorResources.Decompilation_log}
{string.Format(CSharpEditorResources._0_items_in_cache, 6)}
------------------
{string.Format(CSharpEditorResources.Resolve_0, "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")}
{string.Format(CSharpEditorResources.Found_single_assembly_0, "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")}
{string.Format(CSharpEditorResources.Load_from_0, "mscorlib.v4_6_1038_0.dll")}
#endif",
};

await GenerateAndVerifySourceAsync(metadataSource, symbolName, LanguageNames.CSharp, expected: expected, signaturesOnly: signaturesOnly);
}
}
}
}